|
1 | | -<table> |
2 | | - <tr> |
3 | | - <td><img src = "http://imgur.com/32UFx.jpg" border = "0"></td> |
4 | | - <td> |
5 | | - <h1>javascript-fu</h1> |
6 | | - <h2>isFu</h2> |
7 | | - <h4><em>the art of the curious type checker</em></h4> |
8 | | - <h2>toFu</h2> |
9 | | - <h4><em>the deadly art of the monkey punch</em></h4> |
10 | | - <h2>getFu</h2> |
11 | | - <h4><em>the art of the swift getter</em></h4> |
12 | | - <h2>dateTimeFu</h2> |
13 | | - <h4><em>the art of time and space</em></h4> |
14 | | - <h2>linqFu</h2> |
15 | | - <h4><em>the forbidden art of querying JSON</em></h4> |
16 | | - <br/> |
17 | | - </td> |
18 | | - </tr> |
19 | | -</table> |
20 | | -<h1>what is javascript-fu?</h1> |
21 | | -<p>javascript-fu is a martial arts discipline (library) for node.js and the browser. through mastering the art of javascript-fu you will be a nimble, yet powerful JavaScript developer. a true javascript-fu master can avoid the bad parts of javascript with ninja-like agility and perform quick and devastating blows to produce robust, succinct code that covers a myriad of common functionalities.</p> |
22 | | -<h3>where did javascript-fu come from?</h3> |
23 | | -<p>javascript-fu is the culmination of years of training in the archaic art of javascript. through meticulously studying the following ancient scrolls we have divined the ultimate form of javascript martial arts. </p> |
| 1 | +## how do i use javascript-fu? |
24 | 2 |
|
25 | | -<p> |
26 | | - <a href = "http://github.com/documentcloud/underscore" target = "_blank">Underscore.js</a>, <a href = "http://jquery.com/" target = "_blank">jQuery.js</a>, <a href = "http://www.datejs.com/" target = "_blank">date.js</a>, <a href = "http://webcache.googleusercontent.com/search?q=cache:AW7__qeq1xMJ:api.rubyonrails.org/classes/Inflector.html+rails+inflectors&cd=1&hl=en&ct=clnk&gl=us" target = "_blank">Rails Inflectors</a>, |
27 | | -Coldfusion's <a href = "http://www.adobe.com/livedocs/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000441.htm" target = "_blank">DateFormat</a> and <a href "http://www.adobe.com/livedocs/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000441.htm" target = "_blank">TimeFormat</a>, Microsoft's <a href = "http://en.wikipedia.org/wiki/Language_Integrated_Query" target = "_blank">LINQ</a> |
| 3 | +[if you don't like reading documentation, check out the interactive javascript-fu demo](http://maraksquires.com/javascript-fu/) |
28 | 4 |
|
| 5 | +### browser |
29 | 6 |
|
30 | | -<h2>how do i use javascript-fu?</h2> |
31 | | -<a href = "http://maraksquires.com/javascript-fu/">if you don't like reading documentation, check out the interactive javascript-fu demo</a> |
32 | | - |
33 | | -<h3>browser</h3> |
34 | | - |
35 | | - <script src = "js-fu.js" type = "text/javascript"></script> |
36 | | - <script> |
37 | | - var x = fu.isNumber(13); // true |
38 | | - var x = fu.isDate('07/01/2010'); // true |
39 | | - </script> |
40 | | - |
41 | | -<h3>node.js </h3> |
42 | | - var fu = require('./js-fu'); |
| 7 | + <script src = "js-fu.js" type = "text/javascript"></script> |
| 8 | + <script> |
43 | 9 | var x = fu.isNumber(13); // true |
44 | 10 | var x = fu.isDate('07/01/2010'); // true |
| 11 | + </script> |
45 | 12 |
|
46 | | -once you have required the js-fu library, you have access to the "fu" object. inside this object you will find ... |
47 | | - |
48 | | -<div align = "center"><h1>the five disciplines of javascript-fu</h1></div> |
49 | | -<h2>isFu - the art of the curious type checker</h2> |
50 | | -isFu methods will accept <em>anything</em> as an argument and gracefully return true or false depending on if the arguments match the type you have checked for |
51 | | -<ul><li>isArray</li><li>isBoolean</li><li>isDate</li><li>isDefined</li><li>isEmpty</li><li>isEqual</li><li>isFunction</li><li>isJSON</li><li>isNode</li><li>isNull</li><li>isNumber</li><li>isObject</li><li>isRegExp</li><li>isString</li><li>isText</li></ul> |
52 | | -<h2>toFu - the deadly art of the monkey punch</h2> |
53 | | -toFu methods will accept <em>anything</em> as an argument and aggressively attempt to coerce the value into the type you have specified |
54 | | -<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> |
55 | | -<h2>getFu - the art of the swift getter</h2> |
56 | | -<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> |
57 | | -<h2>dateTimeFu - the art of space and time</h2> |
58 | | -<a href = "#">Try out the interactive demo of Date.format()</a> |
59 | | - |
60 | | -dateTimeFu adds a new method "format" to the built in JavaScript Date object |
61 | | - |
62 | | -Date.format() takes one argument, a formatting mask<br/> |
63 | | -you can use a pre-defined formatting mask or an inline mask. you can also define new re-usable masks |
64 | | - |
65 | | - var now = new Date(); |
66 | | - now.format("shortDate"); // ouputs: 7/1/10 |
67 | | - now.format("mm/dd/yyyy"); // outputs: 07/01/2010 |
68 | | - |
| 13 | +### node.js |
69 | 14 |
|
70 | | -<h3>pre-defined dateTime masks</h3> |
| 15 | + var fu = require('./js-fu'); |
| 16 | + var x = fu.isNumber(13); // true |
| 17 | + var x = fu.isDate('07/01/2010'); // true |
71 | 18 |
|
72 | | -<table cellspacing="0" summary="Date Format named masks"> |
73 | | - <thead> |
74 | | - <tr> |
75 | | - <th>Name</th> |
76 | | - <th>Mask</th> |
77 | | - <th>Example</th> |
78 | | - </tr> |
79 | | - </thead> |
80 | | - <tbody> |
81 | | - <tr> |
82 | | - <td>default</td> |
83 | | - <td>ddd mmm dd yyyy HH:MM:ss</td> |
84 | | - <td>Sat Jun 09 2010 17:46:21</td> |
85 | | - </tr> |
86 | | - <tr class="altBg"> |
87 | | - <td>shortDate</td> |
88 | | - <td>m/d/yy</td> |
89 | | - <td>6/9/07</td> |
90 | | - </tr> |
91 | | - <tr> |
92 | | - <td>mediumDate</td> |
93 | | - <td>mmm d, yyyy</td> |
94 | | - <td>Jun 9, 2010</td> |
95 | | - </tr> |
96 | | - <tr class="altBg"> |
97 | | - <td>longDate</td> |
98 | | - <td>mmmm d, yyyy</td> |
99 | | - <td>June 9, 2010</td> |
100 | | - </tr> |
101 | | - <tr> |
102 | | - <td>fullDate</td> |
103 | | - <td>dddd, mmmm d, yyyy</td> |
104 | | - <td>Saturday, June 9, 2010</td> |
105 | | - </tr> |
106 | | - <tr class="altBg"> |
107 | | - <td>shortTime</td> |
108 | | - <td>h:MM TT</td> |
109 | | - <td>5:46 PM</td> |
110 | | - </tr> |
111 | | - <tr> |
112 | | - <td>mediumTime</td> |
113 | | - <td>h:MM:ss TT</td> |
114 | | - <td>5:46:21 PM</td> |
115 | | - </tr> |
116 | | - <tr class="altBg"> |
117 | | - <td>longTime</td> |
118 | | - <td>h:MM:ss TT Z</td> |
119 | | - <td>5:46:21 PM EST</td> |
120 | | - </tr> |
121 | | - <tr> |
122 | | - <td>isoDate</td> |
123 | | - <td>yyyy-mm-dd</td> |
124 | | - <td>2010-06-09</td> |
125 | | - </tr> |
126 | | - <tr class="altBg"> |
127 | | - <td>isoTime</td> |
128 | | - <td>HH:MM:ss</td> |
129 | | - <td>17:46:21</td> |
130 | | - </tr> |
131 | | - <tr> |
132 | | - <td>isoDateTime</td> |
133 | | - <td>yyyy-mm-dd'T'HH:MM:ss</td> |
134 | | - <td>2010-06-09T17:46:21</td> |
135 | | - </tr> |
136 | | - <tr class="altBg"> |
137 | | - <td>isoUtcDateTime</td> |
138 | | - <td>UTC:yyyy-mm-dd'T'HH:MM:ss'Z'</td> |
139 | | - <td>2010-06-09T22:46:21Z</td> |
140 | | - </tr> |
141 | | - </tbody> |
142 | | -</table> |
143 | | - |
144 | | - |
145 | | -<h3>custom dateTime masks</h3> |
146 | | - |
147 | | -<table cellspacing="0" summary="Date Format mask metasequences"> |
148 | | - <thead> |
149 | | - <tr> |
150 | | - <th>Mask</th> |
151 | | - <th>Description</th> |
152 | | - </tr> |
153 | | - </thead> |
154 | | - <tbody> |
155 | | - <tr> |
156 | | - <td><code>d</code></td> |
157 | | - <td>Day of the month as digits; no leading zero for single-digit days.</td> |
158 | | - </tr> |
159 | | - <tr class="altBg"> |
160 | | - <td><code>dd</code></td> |
161 | | - <td>Day of the month as digits; leading zero for single-digit days.</td> |
162 | | - </tr> |
163 | | - <tr> |
164 | | - <td><code>ddd</code></td> |
165 | | - <td>Day of the week as a three-letter abbreviation.</td> |
166 | | - </tr> |
167 | | - <tr class="altBg"> |
168 | | - <td><code>dddd</code></td> |
169 | | - <td>Day of the week as its full name.</td> |
170 | | - </tr> |
171 | | - <tr> |
172 | | - <td><code>m</code></td> |
173 | | - <td>Month as digits; no leading zero for single-digit months.</td> |
174 | | - </tr> |
175 | | - <tr class="altBg"> |
176 | | - <td><code>mm</code></td> |
177 | | - <td>Month as digits; leading zero for single-digit months.</td> |
178 | | - </tr> |
179 | | - <tr> |
180 | | - <td><code>mmm</code></td> |
181 | | - <td>Month as a three-letter abbreviation.</td> |
182 | | - </tr> |
183 | | - <tr class="altBg"> |
184 | | - <td><code>mmmm</code></td> |
185 | | - <td>Month as its full name.</td> |
186 | | - </tr> |
187 | | - <tr> |
188 | | - <td><code>yy</code></td> |
189 | | - <td>Year as last two digits; leading zero for years less than 10.</td> |
190 | | - </tr> |
191 | | - <tr class="altBg"> |
192 | | - <td><code>yyyy</code></td> |
193 | | - <td>Year represented by four digits.</td> |
194 | | - </tr> |
195 | | - <tr> |
196 | | - <td><code>h</code></td> |
197 | | - <td>Hours; no leading zero for single-digit hours (12-hour clock).</td> |
198 | | - </tr> |
199 | | - <tr class="altBg"> |
200 | | - <td><code>hh</code></td> |
201 | | - <td>Hours; leading zero for single-digit hours (12-hour clock).</td> |
202 | | - </tr> |
203 | | - <tr> |
204 | | - <td><code>H</code></td> |
205 | | - <td>Hours; no leading zero for single-digit hours (24-hour clock).</td> |
206 | | - </tr> |
207 | | - <tr class="altBg"> |
208 | | - <td><code>HH</code></td> |
209 | | - <td>Hours; leading zero for single-digit hours (24-hour clock).</td> |
210 | | - </tr> |
211 | | - <tr> |
212 | | - <td><code>M</code></td> |
213 | | - <td>Minutes; no leading zero for single-digit minutes.<br> |
214 | | - <span class="small">Uppercase M unlike CF <code>timeFormat</code>'s m to avoid conflict with months.</span></td> |
215 | | - </tr> |
216 | | - <tr class="altBg"> |
217 | | - <td><code>MM</code></td> |
218 | | - <td>Minutes; leading zero for single-digit minutes.<br> |
219 | | - <span class="small">Uppercase MM unlike CF <code>timeFormat</code>'s mm to avoid conflict with months.</span></td> |
220 | | - </tr> |
221 | | - <tr> |
222 | | - <td><code>s</code></td> |
223 | | - <td>Seconds; no leading zero for single-digit seconds.</td> |
224 | | - </tr> |
225 | | - <tr class="altBg"> |
226 | | - <td><code>ss</code></td> |
227 | | - <td>Seconds; leading zero for single-digit seconds.</td> |
228 | | - </tr> |
229 | | - <tr> |
230 | | - <td><code>l</code> <em>or</em> <code>L</code></td> |
231 | | - <td>Milliseconds. <code>l</code> gives 3 digits. <code>L</code> gives 2 digits.</td> |
232 | | - </tr> |
233 | | - <tr class="altBg"> |
234 | | - <td><code>t</code></td> |
235 | | - <td>Lowercase, single-character time marker string: <em>a</em> or <em>p</em>.<br> |
236 | | - <span class="small">No equivalent in CF.</span></td> |
237 | | - </tr> |
238 | | - <tr> |
239 | | - <td><code>tt</code></td> |
240 | | - <td>Lowercase, two-character time marker string: <em>am</em> or <em>pm</em>.<br> |
241 | | - <span class="small">No equivalent in CF.</span></td> |
242 | | - </tr> |
243 | | - <tr class="altBg"> |
244 | | - <td><code>T</code></td> |
245 | | - <td>Uppercase, single-character time marker string: <em>A</em> or <em>P</em>.<br> |
246 | | - <span class="small">Uppercase T unlike CF's t to allow for user-specified casing.</span></td> |
247 | | - </tr> |
248 | | - <tr> |
249 | | - <td><code>TT</code></td> |
250 | | - <td>Uppercase, two-character time marker string: <em>AM</em> or <em>PM</em>.<br> |
251 | | - <span class="small">Uppercase TT unlike CF's tt to allow for user-specified casing.</span></td> |
252 | | - </tr> |
253 | | - <tr class="altBg"> |
254 | | - <td><code>Z</code></td> |
255 | | - <td>US timezone abbreviation, e.g. <em>EST</em> or <em>MDT</em>. With non-US timezones or in the Opera browser, the GMT/UTC offset is returned, e.g. <em>GMT-0500</em><br> |
256 | | - <span class="small">No equivalent in CF.</span></td> |
257 | | - </tr> |
258 | | - <tr> |
259 | | - <td><code>o</code></td> |
260 | | - <td>GMT/UTC timezone offset, e.g. <em>-0500</em> or <em>+0230</em>.<br> |
261 | | - <span class="small">No equivalent in CF.</span></td> |
262 | | - </tr> |
263 | | - <tr class="altBg"> |
264 | | - <td><code>S</code></td> |
265 | | - <td>The date's ordinal suffix (<em>st</em>, <em>nd</em>, <em>rd</em>, or <em>th</em>). Works well with <code>d</code>.<br> |
266 | | - <span class="small">No equivalent in CF.</span></td> |
267 | | - </tr> |
268 | | - <tr> |
269 | | - <td><code>'...'</code> <em>or</em> <code>"..."</code></td> |
270 | | - <td>Literal character sequence. Surrounding quotes are removed.<br> |
271 | | - <span class="small">No equivalent in CF.</span></td> |
272 | | - </tr> |
273 | | - <tr class="altBg"> |
274 | | - <td><code>UTC:</code></td> |
275 | | - <td>Must be the first four characters of the mask. Converts the date from local time to UTC/GMT/Zulu time before applying the mask. The "UTC:" prefix is removed.<br> |
276 | | - <span class="small">No equivalent in CF.</span></td> |
277 | | - </tr> |
278 | | - </tbody> |
279 | | -</table> |
280 | | - |
281 | | -<h2>linqFu - the forbidden art of querying JSON with LINQ, liberated from...<em>Microsoft</em></h2> |
282 | | -<a href = "http://maraksquires.com/JSLINQ/">Try out the interactive demo of JSLINQ</a> <br/> |
283 | | -linqFu is adds the <a href = "http://github.com/marak/jslinq">JSLINQ project</a> which is a pure javascript implementation of <em>gasp</em> Microsoft's <a href = "http://en.wikipedia.org/wiki/Language_Integrated_Query">LINQ</a> query language. it's very usefull for quickly querying JSON objects. |
284 | | -###simple Select |
285 | | - var sample = fu.linq(sampleData). |
286 | | - Select(function (item) {return item.FirstName;}); |
287 | | - output: {"items":["Chris","Kate","Josh","John","Steve","Katie","Dirk","Chris","Bernard","Kate"]} |
288 | | -###simple Select with OrderBy |
289 | | - var sample = fu.linq(sampleData). |
290 | | - Select(function (item) {return item.FirstName;}). |
291 | | - OrderBy(function (item) {return item;}); |
292 | | - output: {"items":["Bernard","Chris","Chris","Dirk","John","Josh","Kate","Kate","Katie","Steve"]} |
293 | | -###simple Where |
294 | | - var sample = fu.linq(sampleData).Where(function (item) {return item.FirstName == "Chris";}); |
295 | | - output: [ |
296 | | - {"ID":1,"FirstName":"Chris","LastName":"Pearson","BookIDs":[1001,1002,1003]}, |
297 | | - {"ID":8,"FirstName":"Chris","LastName":"Stevenson","BookIDs":[4001,4002,4003]} |
298 | | - ] |
299 | | -###For the Full JSLINQ Demo and API implementation goto @ [http://maraksquires.com/JSLINQ/](http://maraksquires.com/JSLINQ/) |
300 | | -<h2>Authors</h2> |
301 | | -<h4>Marak Squires, Aaron Blohowiak, Matthew Bergman</h4> |
| 19 | +once you have required the js-fu library, you have access to the "fu" object. inside this object you will find ... |
| 20 | + |
0 commit comments