Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:Marak/javascript-fu

  • Loading branch information...
commit ef60bf50973088bd9778474cf17990a6b4747134 2 parents b6062ff + f86d35b
@Marak authored
View
2  Readme.md
@@ -57,7 +57,7 @@ isFu methods will accept <em>anything</em> as an argument and gracefully return
toFu methods will accept <em>anything</em> as an argument and aggressively attempt to coerce the value into the type you have specified
<ul><li>toCamel</li><li>toChain</li><li>toDash</li><li>toHuman</li><li>toJSON</li><li>toLink</li><li>toMix</li><li>toNumber</li><li>toOrdinal</li><li>toParam</li><li>toPercent</li><li>toPlural</li><li>toReverse</li><li>toShuffle</li><li>toSingle</li><li>toTitle</li><li>toTrim</li><li>toUnderscore</li><li>toWrap</li></ul>
<h2>getFu - the art of the swift getter</h2>
-<ul><li>getMinutes</li><li>getMonth</li><li>getSeconds</li><li>getFirst</li><li>getFunctions</li><li>getIndex</li><li>getKeys</li><li>getLast</li><li>getLeft</li><li>getLinks</li><li>getNode</li><li>getRandom</li><li>getRight</li><li>getValues</li></ul>
+<ul><li>getFirst</li><li>getFunctions</li><li>getIndex</li><li>getKeys</li><li>getLast</li><li>getLeft</li><li>getLinks</li><li>getNode</li><li>getRandom</li><li>getRight</li><li>getValues</li></ul>
<h2>dateTimeFu - the art of space and time</h2>
<a href = "#">Try out the interactive demo of Date.format()</a><br/>
View
2  build/docs/index.js
@@ -57,7 +57,7 @@ isFu methods will accept <em>anything</em> as an argument and gracefully return
toFu methods will accept <em>anything</em> as an argument and aggressively attempt to coerce the value into the type you have specified
<ul><li>toCamel</li><li>toChain</li><li>toDash</li><li>toHuman</li><li>toJSON</li><li>toLink</li><li>toMix</li><li>toNumber</li><li>toOrdinal</li><li>toParam</li><li>toPercent</li><li>toPlural</li><li>toReverse</li><li>toShuffle</li><li>toSingle</li><li>toTitle</li><li>toTrim</li><li>toUnderscore</li><li>toWrap</li></ul>
<h2>getFu - the art of the swift getter</h2>
-<ul><li>getMinutes</li><li>getMonth</li><li>getSeconds</li><li>getFirst</li><li>getFunctions</li><li>getIndex</li><li>getKeys</li><li>getLast</li><li>getLeft</li><li>getLinks</li><li>getNode</li><li>getRandom</li><li>getRight</li><li>getValues</li></ul>
+<ul><li>getFirst</li><li>getFunctions</li><li>getIndex</li><li>getKeys</li><li>getLast</li><li>getLeft</li><li>getLinks</li><li>getNode</li><li>getRandom</li><li>getRight</li><li>getValues</li></ul>
<h2>dateTimeFu - the art of space and time</h2>
<a href = "#">Try out the interactive demo of Date.format()</a><br/>
View
59 lib/getFu.js
@@ -1,4 +1,5 @@
-var isFu = require("./isFu")
+var isFu = require("./isFu");
+var toFu = require("./toFu");
/*
@@ -14,18 +15,20 @@ exports.getRight = function( str, n ){
*/
-
-// returns DOM nodes
-exports.getNode = function ( selector ){
- // TODO : add queryselectorall check and jquery check then default to a basic id lookup
- return str;
-};
+// Docs
+var D = {};
exports.getRandom = function(range) {
r = Math.floor(Math.random()*range);
return r;
};
+D.getRandom = {
+ "example":"getRandom( range );",
+ "message":"picks a random number from a range",
+ "code":exports.getRandom.toString()
+};
+
exports.getKeys = function( object ) {
keys = [];
for (var key in object) {
@@ -34,6 +37,12 @@ exports.getKeys = function( object ) {
return keys;
};
+D.getKeys = {
+ "example":"getKeys( object );",
+ "message":"returns an array of keys for an object",
+ "code":exports.getKeys.toString()
+};
+
exports.getValues = function( object ) {
values = [];
for (var key in object) {
@@ -42,16 +51,48 @@ exports.getValues = function( object ) {
return values;
};
+D.getValues = {
+ "example":"getValues( object );",
+ "message":"returns an array of values for an object",
+ "code":exports.getValues.toString()
+};
+
+exports.getRight = function(string, n) {
+ return string.substring(n, string.length);
+};
+
+D.getRight = {
+ "example":"getRight(string, character_index );",
+ "message":"returns a substring to the right of character position given",
+ "code":exports.getRight.toString()
+};
+
+exports.getLeft = function(string, n) {
+ return toFu.toReverse(toFu.toReverse(string).substring(0, n));
+};
+
+D.getLeft = {
+ "example":"getLeft(string, character_index );",
+ "message":"returns a substring to the left of character position given",
+ "code":exports.getLeft.toString()
+};
+
// If the browser doesn't supply us with indexOf (I'm looking at you, MSIE),
// we need this function. Return the position of the first occurence of an
// item in an array, or -1 if the item is not included in the array.
// Delegates to JavaScript 1.8's native indexOf if available.
exports.getIndex = function( array, item ){
- for (var i = 0, l = array.length; i < l; i++) if (array[i] === item) return i;
+ for (var i = 0, l = array.length; i < l; i++) if (isFu.isEqual(array[i], item)) return i;
return -1;
};
+D.getIndex = {
+ "example":"getIndex(array, object );",
+ "message":"returns index of object's placement in array",
+ "code":exports.getIndex.toString()
+};
+
// Returns a sorted list of the names of every method in an object — that is to say, the name of every function property of the object.
exports.getFunctions = function( object ){
// todo add check for iterating through an object and returning an array of all functions (isFunction())
-}
+};
View
16 lib/isFu.js
@@ -118,8 +118,7 @@ exports.isArray = function(obj){
D.isArray = {
"example":"isArray( anything );",
"message":"checks if anything is array",
- "code":exports.isArray.toString(),
- "tests":[]
+ "code":exports.isArray.toString()
};
exports.isJSON = function(jsony){
@@ -128,8 +127,7 @@ exports.isJSON = function(jsony){
D.isJSON = {
"example":"isJSON( anything );",
"message":"checks if anything is a JSON string",
- "code":exports.isJSON.toString(),
- "tests":[]
+ "code":exports.isJSON.toString()
};
@@ -137,6 +135,7 @@ exports.isNaN = function(obj) {
return this.isNumber(obj) && isNaN(obj);
};
+
exports.isObject = function(objecty){
if(this.isFunction(objecty)) {
return false;
@@ -149,8 +148,7 @@ exports.isObject = function(objecty){
D.isObject = {
"example":"isObject( anything );",
"message":"checks if anything is an object",
- "code":exports.isObject.toString(),
- "tests":[]
+ "code":exports.isObject.toString()
};
@@ -160,8 +158,7 @@ exports.isFunction = function(functiony){
D.isFunction = {
"example":"isFunction( anything );",
"message":"checks if anything is a function",
- "code":exports.isFunction.toString(),
- "tests":[]
+ "code":exports.isFunction.toString()
};
exports.isEmpty = function(obj){
@@ -177,8 +174,7 @@ exports.isEmpty = function(obj){
D.isFunction = {
"example":"isEmpty( anything );",
"message":"checks if anything is empty",
- "code":exports.isFunction.toString(),
- "tests":[]
+ "code":exports.isFunction.toString()
};
exports.isNode = function(){
View
33 test/getFu-test.js
@@ -29,7 +29,36 @@ vows.describe('format.js lib/getFu').addBatch({
assert.ok( false, '"' + result.join(", ") + '"' + ' are not the values');
}
}
+ },
+ "getRight()": {
+ topic: "I am a very model of a model major general",
+ "extracted right of string":function( string ){
+ var result = format.getFu.getRight(string, 7);
+ assert.equal(result, "very model of a model major general");
+ }
+ },
+ "getLeft()": {
+ topic: "I am a very model of a model major general",
+ "extracted left of string":function( string ){
+ var result = format.getFu.getLeft(string, 7);
+ assert.equal(result, "general");
+ }
+ },
+ "getIndex()": {
+ "on complex object": {
+ topic: ["I", "am", "a", [1,2,3]],
+ "extracted index if complex object from arra":function( array ){
+ var result = format.getFu.getIndex(array, [1,2,3]);
+ assert.equal(result, 3);
+ }
+ },
+ "on complex object": {
+ topic: ["I", "am", "a", [1,2,3]],
+ "extracted index if simple object from arra":function( array ){
+ var result = format.getFu.getIndex(array, "am");
+ assert.equal(result, 1);
+ }
+ }
}
-
-}).export(module);
+}).run();
Please sign in to comment.
Something went wrong with that request. Please try again.