Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Marak/javascript-fu
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Jul 16, 2010
2 parents b6062ff + f86d35b commit ef60bf5
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Expand Up @@ -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/>

Expand Down
2 changes: 1 addition & 1 deletion build/docs/index.js
Expand Up @@ -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/>

Expand Down
59 changes: 50 additions & 9 deletions lib/getFu.js
@@ -1,4 +1,5 @@
var isFu = require("./isFu")
var isFu = require("./isFu");
var toFu = require("./toFu");

/*
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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())
}
};
16 changes: 6 additions & 10 deletions lib/isFu.js
Expand Up @@ -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){
Expand All @@ -128,15 +127,15 @@ 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()
};


exports.isNaN = function(obj) {
return this.isNumber(obj) && isNaN(obj);
};


exports.isObject = function(objecty){
if(this.isFunction(objecty)) {
return false;
Expand All @@ -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()
};


Expand All @@ -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){
Expand All @@ -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(){
Expand Down
33 changes: 31 additions & 2 deletions test/getFu-test.js
Expand Up @@ -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();

0 comments on commit ef60bf5

Please sign in to comment.