Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit ef60bf50973088bd9778474cf17990a6b4747134 2 parents b6062ff + f86d35b
authored
2  Readme.md
Source Rendered
@@ -57,7 +57,7 @@ isFu methods will accept <em>anything</em> as an argument and gracefully return
57 57
 toFu methods will accept <em>anything</em> as an argument and aggressively attempt to coerce the value into the type you have specified 
58 58
 <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>
59 59
 <h2>getFu - the art of the swift getter</h2>
60  
-<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>
  60
+<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>
61 61
 <h2>dateTimeFu - the art of space and time</h2>
62 62
 <a href = "#">Try out the interactive demo of Date.format()</a><br/>
63 63
 
2  build/docs/index.js
@@ -57,7 +57,7 @@ isFu methods will accept <em>anything</em> as an argument and gracefully return
57 57
 toFu methods will accept <em>anything</em> as an argument and aggressively attempt to coerce the value into the type you have specified 
58 58
 <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>
59 59
 <h2>getFu - the art of the swift getter</h2>
60  
-<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>
  60
+<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>
61 61
 <h2>dateTimeFu - the art of space and time</h2>
62 62
 <a href = "#">Try out the interactive demo of Date.format()</a><br/>
63 63
 
59  lib/getFu.js
... ...
@@ -1,4 +1,5 @@
1  
-var isFu = require("./isFu")
  1
+var isFu = require("./isFu");
  2
+var toFu = require("./toFu");
2 3
 
3 4
 /*
4 5
 
@@ -14,18 +15,20 @@ exports.getRight = function( str, n ){
14 15
 
15 16
 */
16 17
 
17  
-
18  
-// returns DOM nodes
19  
-exports.getNode = function ( selector ){
20  
-  // TODO : add queryselectorall check and jquery check then default to a basic id lookup
21  
-  return str;
22  
-};
  18
+// Docs
  19
+var D = {};
23 20
 
24 21
 exports.getRandom = function(range) {
25 22
 		r = Math.floor(Math.random()*range);
26 23
 		return r;
27 24
 };
28 25
 
  26
+D.getRandom = {
  27
+  "example":"getRandom( range );",
  28
+  "message":"picks a random number from a range",
  29
+  "code":exports.getRandom.toString()
  30
+};
  31
+
29 32
 exports.getKeys = function( object ) {
30 33
   keys = [];
31 34
   for (var key in object) {
@@ -34,6 +37,12 @@ exports.getKeys = function( object ) {
34 37
   return keys;
35 38
 };
36 39
 
  40
+D.getKeys = {
  41
+  "example":"getKeys( object );",
  42
+  "message":"returns an array of keys for an object",
  43
+  "code":exports.getKeys.toString()
  44
+};
  45
+
37 46
 exports.getValues = function( object ) {
38 47
   values = [];
39 48
    for (var key in object) {
@@ -42,16 +51,48 @@ exports.getValues = function( object ) {
42 51
    return values;
43 52
 };
44 53
 
  54
+D.getValues = {
  55
+  "example":"getValues( object );",
  56
+  "message":"returns an array of values for an object",
  57
+  "code":exports.getValues.toString()
  58
+};
  59
+
  60
+exports.getRight = function(string, n) {
  61
+  return string.substring(n, string.length);
  62
+};
  63
+
  64
+D.getRight = {
  65
+  "example":"getRight(string, character_index );",
  66
+  "message":"returns a substring to the right of character position given",
  67
+  "code":exports.getRight.toString()
  68
+};
  69
+
  70
+exports.getLeft = function(string, n) {
  71
+  return toFu.toReverse(toFu.toReverse(string).substring(0, n));
  72
+};
  73
+
  74
+D.getLeft = {
  75
+  "example":"getLeft(string, character_index );",
  76
+  "message":"returns a substring to the left of character position given",
  77
+  "code":exports.getLeft.toString()
  78
+};
  79
+
45 80
 // If the browser doesn't supply us with indexOf (I'm looking at you, MSIE),
46 81
 // we need this function. Return the position of the first occurence of an
47 82
 // item in an array, or -1 if the item is not included in the array.
48 83
 // Delegates to JavaScript 1.8's native indexOf if available.
49 84
 exports.getIndex = function( array, item ){
50  
-   for (var i = 0, l = array.length; i < l; i++) if (array[i] === item) return i;
  85
+   for (var i = 0, l = array.length; i < l; i++) if (isFu.isEqual(array[i], item)) return i;
51 86
    return -1;
52 87
 };
53 88
 
  89
+D.getIndex = {
  90
+  "example":"getIndex(array, object );",
  91
+  "message":"returns index of object's placement in array",
  92
+  "code":exports.getIndex.toString()
  93
+};
  94
+
54 95
 // 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.
55 96
 exports.getFunctions = function( object ){
56 97
  // todo add check for iterating through an object and returning an array of all functions (isFunction())  
57  
-}
  98
+};
16  lib/isFu.js
@@ -118,8 +118,7 @@ exports.isArray = function(obj){
118 118
 D.isArray = {
119 119
   "example":"isArray( anything );",
120 120
   "message":"checks if anything is array",
121  
-  "code":exports.isArray.toString(),
122  
-  "tests":[]
  121
+  "code":exports.isArray.toString()
123 122
 };
124 123
 
125 124
 exports.isJSON = function(jsony){
@@ -128,8 +127,7 @@ exports.isJSON = function(jsony){
128 127
 D.isJSON = {
129 128
   "example":"isJSON( anything );",
130 129
   "message":"checks if anything is a JSON string",
131  
-  "code":exports.isJSON.toString(),
132  
-  "tests":[]
  130
+  "code":exports.isJSON.toString()
133 131
 };
134 132
 
135 133
 
@@ -137,6 +135,7 @@ exports.isNaN = function(obj) {
137 135
   return this.isNumber(obj) && isNaN(obj);
138 136
 };
139 137
 
  138
+
140 139
 exports.isObject = function(objecty){
141 140
 	if(this.isFunction(objecty)) {
142 141
 		return false; 
@@ -149,8 +148,7 @@ exports.isObject = function(objecty){
149 148
 D.isObject = {
150 149
   "example":"isObject( anything );",
151 150
   "message":"checks if anything is an object",
152  
-  "code":exports.isObject.toString(),
153  
-  "tests":[]
  151
+  "code":exports.isObject.toString()
154 152
 };
155 153
 
156 154
 
@@ -160,8 +158,7 @@ exports.isFunction = function(functiony){
160 158
 D.isFunction = {
161 159
   "example":"isFunction( anything );",
162 160
   "message":"checks if anything is a function",
163  
-  "code":exports.isFunction.toString(),
164  
-  "tests":[]
  161
+  "code":exports.isFunction.toString()
165 162
 };
166 163
 
167 164
 exports.isEmpty = function(obj){
@@ -177,8 +174,7 @@ exports.isEmpty = function(obj){
177 174
 D.isFunction = {
178 175
   "example":"isEmpty( anything );",
179 176
   "message":"checks if anything is empty",
180  
-  "code":exports.isFunction.toString(),
181  
-  "tests":[]
  177
+  "code":exports.isFunction.toString()
182 178
 };
183 179
 
184 180
 exports.isNode = function(){
33  test/getFu-test.js
@@ -29,7 +29,36 @@ vows.describe('format.js lib/getFu').addBatch({
29 29
         assert.ok( false, '"' + result.join(", ") + '"' + ' are not the values');
30 30
       }
31 31
     }
  32
+  },
  33
+  "getRight()": {
  34
+     topic: "I am a very model of a model major general",
  35
+    "extracted right of string":function( string ){
  36
+      var result = format.getFu.getRight(string, 7);
  37
+     assert.equal(result, "very model of a model major general");
  38
+    }
  39
+  },
  40
+  "getLeft()": {
  41
+     topic: "I am a very model of a model major general",
  42
+    "extracted left of string":function( string ){
  43
+      var result = format.getFu.getLeft(string, 7);
  44
+     assert.equal(result, "general");
  45
+    }
  46
+  },
  47
+  "getIndex()": {
  48
+    "on complex object": {
  49
+       topic: ["I", "am", "a", [1,2,3]],
  50
+      "extracted index if complex object from arra":function( array ){
  51
+        var result = format.getFu.getIndex(array, [1,2,3]);
  52
+       assert.equal(result, 3);
  53
+      }
  54
+    },
  55
+    "on complex object": {
  56
+       topic: ["I", "am", "a", [1,2,3]],
  57
+      "extracted index if simple object from arra":function( array ){
  58
+        var result = format.getFu.getIndex(array, "am");
  59
+       assert.equal(result, 1);
  60
+      }
  61
+    }
32 62
   }
33 63
 
34  
-
35  
-}).export(module);
  64
+}).run();

0 notes on commit ef60bf5

Please sign in to comment.
Something went wrong with that request. Please try again.