#(unreleased / unfinished. donut use.)
![]() |
|
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.
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.
Underscore.js, jQuery.js, date.js, Rails Inflectors, Coldfusion's DateFormat and TimeFormat, Microsoft's LINQ
if you don't like reading documentation, check out the interactive javascript-fu demo <script src = "js-fu.js" type = "text/javascript"></script>
<script>
var x = fu.isNumber(13); // true
var x = fu.isDate('07/01/2010'); // true
</script>
var fu = require('./js-fu');
var x = fu.isNumber(13); // true
var x = fu.isDate('07/01/2010'); // true
once you have required the js-fu library, you have access to the "fu" object. inside this object you will find ...
isFu methods will accept anything as an argument and gracefully return true or false depending on if the arguments match the type you have checked for- isArray
- isBoolean
- isDate
- isDefined
- isEmpty
- isEqual
- isFunction
- isJSON
- isNode
- isNull
- isNumber
- isObject
- isRegExp
- isString
- isText
- toCamel
- toChain
- toDash
- toHuman
- toJSON
- toLink
- toMix
- toNumber
- toOrdinal
- toParam
- toPercent
- toPlural
- toReverse
- toShuffle
- toSingle
- toTitle
- toTrim
- toUnderscore
- toWrap
- getFirst
- getFunctions
- getIndex
- getKeys
- getLast
- getLeft
- getLinks
- getNode
- getRandom
- getRight
- getValues
dateTimeFu adds a new method "format" to the built in JavaScript Date object
Date.format() takes one argument, a formatting mask
you can use a pre-defined formatting mask or an inline mask. you can also define new re-usable masks
var now = new Date();
now.format("shortDate"); // ouputs: 7/1/10
now.format("mm/dd/yyyy"); // outputs: 07/01/2010
| Name | Mask | Example |
|---|---|---|
| default | ddd mmm dd yyyy HH:MM:ss | Sat Jun 09 2010 17:46:21 |
| shortDate | m/d/yy | 6/9/07 |
| mediumDate | mmm d, yyyy | Jun 9, 2010 |
| longDate | mmmm d, yyyy | June 9, 2010 |
| fullDate | dddd, mmmm d, yyyy | Saturday, June 9, 2010 |
| shortTime | h:MM TT | 5:46 PM |
| mediumTime | h:MM:ss TT | 5:46:21 PM |
| longTime | h:MM:ss TT Z | 5:46:21 PM EST |
| isoDate | yyyy-mm-dd | 2010-06-09 |
| isoTime | HH:MM:ss | 17:46:21 |
| isoDateTime | yyyy-mm-dd'T'HH:MM:ss | 2010-06-09T17:46:21 |
| isoUtcDateTime | UTC:yyyy-mm-dd'T'HH:MM:ss'Z' | 2010-06-09T22:46:21Z |
linqFu is adds the JSLINQ project which is a pure javascript implementation of gasp Microsoft's LINQ query language. it's very usefull for quickly querying JSON objects. var sample = fu.linq(sampleData). Select(function (item) {return item.FirstName;}); output: {"items":["Chris","Kate","Josh","John","Steve","Katie","Dirk","Chris","Bernard","Kate"]}
var sample = fu.linq(sampleData).
Select(function (item) {return item.FirstName;}).
OrderBy(function (item) {return item;});
output: {"items":["Bernard","Chris","Chris","Dirk","John","Josh","Kate","Kate","Katie","Steve"]}
var sample = fu.linq(sampleData).Where(function (item) {return item.FirstName == "Chris";});
output: [
{"ID":1,"FirstName":"Chris","LastName":"Pearson","BookIDs":[1001,1002,1003]},
{"ID":8,"FirstName":"Chris","LastName":"Stevenson","BookIDs":[4001,4002,4003]}
]

