An open API service indexing awesome lists of open source software.

https://github.com/marak/javascript-fu

a javascript martial arts library for node.js and the browser. destroy the bad parts with ninja-like precision
https://github.com/marak/javascript-fu

Last synced: about 1 year ago
JSON representation

a javascript martial arts library for node.js and the browser. destroy the bad parts with ninja-like precision

Awesome Lists containing this project

README

          

#(unreleased / unfinished. donut use.)




javascript-fu


isFu


the art of the curious type checker


toFu


the deadly art of the monkey punch


getFu


the art of the swift getter


dateTimeFu


the art of time and space


linqFu


the forbidden art of querying JSON





what is javascript-fu?


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.


where did javascript-fu come from?


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

how do i use javascript-fu?


if you don't like reading documentation, check out the interactive javascript-fu demo

browser



<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>

node.js


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 ...

the five disciplines of javascript-fu


isFu - the art of the curious type checker


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


toFu - the deadly art of the monkey punch


toFu methods will accept anything as an argument and aggressively attempt to coerce the value into the type you have specified

  • toCamel

  • toChain

  • toDash

  • toHuman

  • toJSON

  • toLink

  • toMix

  • toNumber

  • toOrdinal

  • toParam

  • toPercent

  • toPlural

  • toReverse

  • toShuffle

  • toSingle

  • toTitle

  • toTrim

  • toUnderscore

  • toWrap


getFu - the art of the swift getter



  • getFirst

  • getFunctions

  • getIndex

  • getKeys

  • getLast

  • getLeft

  • getLinks

  • getNode

  • getRandom

  • getRight

  • getValues


dateTimeFu - the art of space and time


Try out the interactive demo of Date.format()

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

pre-defined dateTime masks



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

custom dateTime masks



Mask
Description




d
Day of the month as digits; no leading zero for single-digit days.


dd
Day of the month as digits; leading zero for single-digit days.


ddd
Day of the week as a three-letter abbreviation.


dddd
Day of the week as its full name.


m
Month as digits; no leading zero for single-digit months.


mm
Month as digits; leading zero for single-digit months.


mmm
Month as a three-letter abbreviation.


mmmm
Month as its full name.


yy
Year as last two digits; leading zero for years less than 10.


yyyy
Year represented by four digits.


h
Hours; no leading zero for single-digit hours (12-hour clock).


hh
Hours; leading zero for single-digit hours (12-hour clock).


H
Hours; no leading zero for single-digit hours (24-hour clock).


HH
Hours; leading zero for single-digit hours (24-hour clock).


M
Minutes; no leading zero for single-digit minutes.

Uppercase M unlike CF timeFormat's m to avoid conflict with months.


MM
Minutes; leading zero for single-digit minutes.

Uppercase MM unlike CF timeFormat's mm to avoid conflict with months.


s
Seconds; no leading zero for single-digit seconds.


ss
Seconds; leading zero for single-digit seconds.


l or L
Milliseconds. l gives 3 digits. L gives 2 digits.


t
Lowercase, single-character time marker string: a or p.

No equivalent in CF.


tt
Lowercase, two-character time marker string: am or pm.

No equivalent in CF.


T
Uppercase, single-character time marker string: A or P.

Uppercase T unlike CF's t to allow for user-specified casing.


TT
Uppercase, two-character time marker string: AM or PM.

Uppercase TT unlike CF's tt to allow for user-specified casing.


Z
US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the GMT/UTC offset is returned, e.g. GMT-0500

No equivalent in CF.


o
GMT/UTC timezone offset, e.g. -0500 or +0230.

No equivalent in CF.


S
The date's ordinal suffix (st, nd, rd, or th). Works well with d.

No equivalent in CF.


'...' or "..."
Literal character sequence. Surrounding quotes are removed.

No equivalent in CF.


UTC:
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.

No equivalent in CF.

linqFu - the forbidden art of querying JSON with LINQ, liberated from...Microsoft


Try out the interactive demo of JSLINQ

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.

simple Select


var sample = fu.linq(sampleData).
Select(function (item) {return item.FirstName;});
output: {"items":["Chris","Kate","Josh","John","Steve","Katie","Dirk","Chris","Bernard","Kate"]}


simple Select with OrderBy



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"]}


simple Where



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]}
]


For the Full JSLINQ Demo and API implementation goto @ http://maraksquires.com/JSLINQ/


Authors


Marak Squires, Aaron Blohowiak, Matthew Bergman