Giter Club home page Giter Club logo

ext.js's Introduction

ext.js - JavaScript Extensions & Utilities

High quality JavaScript extensions for various tasks such as formatting dates, currency helpers, and more. This library targets node.js and server-side frameworks such as Express.

Ext.js uses the CommonJS module pattern when needed. Additionally, all of the native object extensions are non-enumerable, and you may create your own via Ext.extend(prototype, methods).

Installation

Install the Kiwi package manager for nodejs and run:

  $ kiwi install ext

Extensions

To use simply: require('ext')

Object

  • Object#keys
  • Object#values
  • Object#join([str])
  • Object#alias(orig, alias)
  • Object#tap(fn[, context])
  • Object#merge(obj[, reverse])
  • Object#each(fn[, context])
  • Object#respondsTo(key)

Array

  • Array#each(fn[, context])
  • Array#excludes(item[, item, ...])
  • Array#includes(item[, item, ...])
  • Array#clear
  • Array#flattened
  • Array#first
  • Array#last
  • Array#sample
  • Array#compact([removableValues])
  • Array#at(index)
  • Array#drop(n)
  • Array#take(n)
  • Array#grep(pattern)
  • Array#remove(obj[, fn[, context]])
  • Array#transposed
  • Array#isEmpty

Collection Operators

  • Array#sum
  • Array#avg
  • Array#min
  • Array#max

Enumerable (included by Object and Array)

  • Enumerable#map(fn[, context])
  • Enumerable#reduce(fn[, memo]) aliased as inject()
  • Enumerable#filter(fn[, context]) aliased as select()
  • Enumerable#detect(fn[, context]) aliased as find()
  • Enumerable#some(fn[, context]) aliased as any()
  • Enumerable#every(fn[, context]) aliased as all()
  • Enumerable#none(fn[, context])
  • Enumerable#reject(fn[, context])

Number

  • Number#ordinalize
  • Number#currency
  • Number#second / Number#seconds
  • Number#minute / Number#minutes
  • Number#hour / Number#hours
  • Number#day / Number#days
  • Number#week / Number#weeks
  • Number#month / Number#months
  • Number#year / Number#years
  • Number#toSeconds
  • Number#toMinutes
  • Number#toHours
  • Number#toDays
  • Number#toWeeks
  • Number#toMonths
  • Number#toYears
  • Number#byte / Number#bytes
  • Number#kilobyte / Number#kilobytes
  • Number#megabyte / Number#megabytes
  • Number#gigabyte / Number#gigabytes
  • Number#ago
  • Number#times(fn[, context])
  • Number#isFloat

String

  • String#variable
  • String#uppercase
  • String#lowercase
  • String#camelcase
  • String#digits
  • String#strip
  • String#drop(n)
  • String#take(n)
  • String#before(str)
  • String#after(str)
  • String#padLeft(width[, char])
  • String#padRight(width[, char])
  • String#remove(pattern)
  • String#startsWith(str)
  • String#endsWith(str)
  • String#capitalize([all])
  • String#wrap(prefix[, suffix])
  • String#singular
  • String#plural
  • String#isPlural
  • String#isSingular
  • String#includes(str)
  • String#count(str)

Date

  • Date#year
  • Date#month
  • Date#date
  • Date#day
  • Date#hours
  • Date#minutes
  • Date#seconds
  • Date#milliseconds
  • Date#monthName
  • Date#shortMonthName
  • Date#dayName
  • Date#shortDayName
  • Date#format(str)
  • Date#inWordsSince(date)
  • Date#inWordsSinceNow
  • Date#parse(str)
  • parse(str[, date])

RegExp

  • RegExp.escape(str[, chars])

Function

  • Function#bind(context[, ...])
  • Function#curry(...)

Base64

  • String#base64Encode / encode(str)
  • String#base64Decode / decode(str)

Error

  • Error.raise([name[, message[, object]]])

MD5

  • String#md5 / hash(str)

printf

  • sprintf(str[, arg[, ...]])
  • eprintf(str[, arg[, ...]])
  • printf(str[, arg[, ...]])

Iterator Functions

Ext.js allows most iterators to use "string lambda expressions", which allows you to define a function by passing a string containing, a valid Lambda expression or shortform as shown in some of the examples below.

Full Lambda Expressions

[1,2,3].map('a -> a + 1')
// => [2,3,4]

Full Lambda Expressions With Currying

curried = [1,2,3].map('a -> b -> a + b')
// => [(Function), (Function), (Function)]

curried[1](40)
// => 42

Literals

[1,2,3,4,5].select(function(n){ return n > 3 })
// => [4,5]

Properties

['hello', 'there'].map('.length')
// => [5,5]

[['hello'], ['there']].map('[0]')
// => ['hello', 'there']

Methods

[1,2,3].map('.toString()')
// => ['1','2','3']

Binary Operators

[1,2,3,4,5].select('> 3')
// => [4,5]

Object Usage

{ foo: 'bar', baz: 'something' }.select(".length > 3")
// => { baz: 'something' }

Date Parsing

The module ext/date exports the parse() function which accepts a string to parse, as well as an optional date which represents "now".

Below are some examples:

new Date
// => Fri, 26 Feb 2010 19:16:47 GMT

parse('today')
// => Fri, 26 Feb 2010 19:16:47 GMT

parse('yesterday')
// => Thu, 25 Feb 2010 19:16:47 GMT

parse('in 5 hours')
// => Sat, 27 Feb 2010 00:16:47 GMT

parse('in 2 days')
// => Sun, 28 Feb 2010 19:16:47 GMT

parse('next tuesday')
// => Tue, 02 Mar 2010 19:16:47 GMT

More examples:

'in a year'
'in one year'
'in five days'
'in three hundred minutes'
'in fifty two minutes'
'in seventy five trillion seconds'
'in five and a half minutes'

Running Tests

$ make test

Contributors

  • TJ Holowaychuk (visionmedia)
  • Tobias Svensson (tobiassvn)

Style Guide

These guidlines must be met before commit(s) or patches will be accepted.

  • Use 2 space indents
  • No trailing whitespace
  • Blank line before EOF
  • Omit semi-colons unless required (very rarely is this needed)
  • Never bump the version

File comments should take the following form:

// ext.js - <category> [- subcategory ...] - Copyright TJ Holowaychuk <[email protected]> (MIT Licensed)

Method comments should take the following form, and 's should be lowercase. "mixed" should be used when multiple types are acceptable, not "object".

When accepting an options object for example, you may use "hash" as this indicates that common usage of this parameter is to pass a literal object using brace syntax.

All examples should be indented 2 spaces.

/**
 * <description>
 *
 *  <example ...>
 *
 * @param  {<type>} <name>
 * @param  {<type>} <name>
 * @param  {<type>} <name>
 * @return {<type>}
 * @api <public|private|protected>
 */

No trailing whitespace after hash keys:

{ foo: 'bar' }
// good

{ foo : 'bar' }
// bad

Hash whitespace:

{ foo: 'bar', baz: 'raz' }
// good

{foo:'bar', baz: 'raz'}
// bad

{
  foo: 'bar',
  baz: 'raz'
}
// good

Chained methods should be indented to indicate context:

str
  .strip
  .replace(...)
  .replace(...)
// good

str
.strip
.replace(...)
.replace(...)
// bad

str.
  strip.
  replace(...).
  replace(...)
// bad

Use single quoted strings when possible:

'yay'
// good

"he said 'yay'"
// good

"yay"
// bad

Large ternary conditional should take the following form:

foo = some.largeProperty === undefined
  ? 'some large value'
  : some.largeProperty + 'whatever'

Conditionals should be functional when possible (I hate braces):

if (foo)
  bar(),
  baz()
else
  if (somethingElse)
    whateves()
// goood

if (foo) {
  bar()
  baz()
}
else {
  if (somethingElse) {
    whateves()
  }
}
// bad

Closures:

function(){
  
}
// good

function () {
  
}
// bad

Methods:

foo.bar = function() {
  
}
// good

foo.bar = function (){
  
}
// bad 

License

(The MIT License)

Copyright (c) 2009 TJ Holowaychuk <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ext.js's People

Contributors

tj avatar fieldkit-zz avatar

Stargazers

Ciaran Jessup avatar Mathieu Ravaux avatar

Watchers

Ciaran Jessup avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.