{"name":"es5-ext","version":"0.8.2","description":"ECMAScript5 extensions","keywords":["ecmascript","ecmascript5","es5","extensions","ext","addons","extras","javascript","util","utils","utilities"],"author":{"name":"Mariusz Nowak","email":"medikoo+es5-ext@medikoo.com","url":"http://www.medikoo.com/"},"main":"lib","repository":{"type":"git","url":"git://github.com/medikoo/es5-ext.git"},"bugs":{"url":"https://github.com/medikoo/es5-ext/issues","email":"medikoo+es5-ext@medikoo.com"},"engines":{"node":">=0.4"},"scripts":{"test":"node ./node_modules/tad/bin/tad lib"},"devDependencies":{"tad":"0.1.x"},"licence":"MIT","dependencies":{},"optionalDependencies":{},"readme":"# es5-ext - ECMAScript5 extensions\n\nMethods, functions and objects that are not part of the standard, written with\nEcmaScript conventions in mind.\n\n## Installation\n\nCan be used in any environment that implements EcmaScript 5th edition.  \nMany extensions will also work with ECMAScript 3rd edition, if they're not let [es5-shim](https://github.com/kriskowal/es5-shim) be your aid.\n\nTo use it with node.js:\n\n\t$ npm install es5-ext\n\nFor browser, you can create custom toolset with help of\n[modules-webmake](https://github.com/medikoo/modules-webmake)\n\n## Usage\n\n__es5-ext__ mostly offer methods (not functions) which can directly be\nassigned to native object's prototype:\n\n\tFunction.prototype.curry = require('es5-ext/lib/Function/prototype/curry');\n\n\tArray.prototype.flatten = require('es5-ext/lib/Array/prototype/flatten');\n\n\tString.prototype.startsWith = require('es5-ext/lib/String/prototype/starts-with');\n\nHowever, extending native prototypes is controversial and in general discouraged,\nmost will agree that __it's ok only if we own the context__ (see\n[extending-javascript-natives](http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/)\nfor more views on that matter).  \nSo when you don't want to extend native prototypes you can use methods as\nfunctions:\n\n\tvar util = {};\n\tvar call = Function.prototype.call;\n\n\tutil.curry = call.bind(require('es5-ext/lib/Function/prototype/curry'));\n\n\tutil.flatten = call.bind(require('es5-ext/lib/Array/prototype/flatten'));\n\n\tutil.startsWith = call.bind(require('es5-ext/lib/String/prototype/starts-with'));\n\nAs with native ones most methods are generic and can be run on any object.\nIn more detail:\n\n* `Array.prototype`, `Number.prototype` and `String.prototype`, methods can be run on any object (any\nvalue that's neither _null_ nor _undefined_),\n* `Date.prototype` methods should be called only on `Date` instances.\n* `Function.prototype` methods can be called on any callable objects (not\nnecessarily functions)\n\nAPI doesn't provide any methods for `Object.prototype` as extending such in any case should be avoided. All `Object` utils are provided as fuctions and most of them expect first input argument to be a valid object (any value that's neither _null_ nor _undefined_).\n\n# API\n\n## Global extensions\n\n### global\n\nObject that represents global scope\n\n### reserved\n\nList of EcmaScript 5th edition reserved keywords.  \nAdditionally under _keywords_, _future_ and _futureStrict_ properties we have lists grouped thematically.\n\n## Array Constructor extensions\n\n### generate([length[, …fill]])\n\nGenerate an array of pregiven _length_ built of repeated arguments.\n\n### from(x)\n\n_In EcmaScript 6th Edition draft_  \nConvert array-like object to an Array\n\n### of([…items])\n\n_In EcmaScript 6th Edition draft_  \nCreate an array from given arguments.\n\n## Array Prototype extensions\n\n### binarySearch(compareFn)\n\nIn __sorted__ list search for index of item for which _compareFn_ returns value closest to _0_.  \nIt's variant of binary search algorithm\n\n### clear()\n\nClears the array\n\n### commonLeft([…lists])\n\nReturns first index at which _lists_ start to differ\n\n### compact()\n\nReturns a copy of the list with all falsy values removed.\n\n### contains(searchElement[, position])\n\nWhether list contains the given value.\n\n### copy()\n\nReturns a copy of the list\n\n### diff(other)\n\nReturns the array of elements that are present in context list but not present in other list.\n\n### eIndexOf(searchElement[, fromIndex])\n\n[_egal_](http://wiki.ecmascript.org/doku.php?id=harmony:egal) version of `indexOf` method\n\n### eLastIndexOf(searchElement[, fromIndex])\n\n[_egal_](http://wiki.ecmascript.org/doku.php?id=harmony:egal) version of `lastIndexOf` method\n\n### exclusion([…lists]])\n\nReturns the array of elements that are found only in context list or lists given in arguments.\n\n### find(query[, thisArg])\n\nReturn first element for which given function returns true\n\n### first()\n\nReturns value for first declared index\n\n### firstIndex()\n\nReturns first declared index of the array\n\n### flatten()\n\nReturns flattened version of the array\n\n### forEachRight(cb[, thisArg])\n\n`forEach` starting from last element\n\n### group(cb[, thisArg])\n\nGroup list elements by value returned by _cb_ function\n\n### indexesOf(searchElement[, fromIndex])\n\nReturns array of all indexes of given value\n\n### intersection([…lists])\n\nComputes the array of values that are the intersection of all lists (context list and lists given in arguments)\n\n### last()\n\nReturns value for last declared index\n\n### lastIndex()\n\nReturns last declared index of the array\n\n### remove(value)\n\nRemove value from the array\n\n### someRight(cb[, thisArg])\n\n`some` starting from last element\n\n### uniq()\n\nReturns duplicate-free version of the array\n\n## Boolean Constructor extensions\n\n### isBoolean(x)\n\nWhether value is boolean\n\n## Date Constructor extensions\n\n### isDate(x)\n\nWhether value is date instance\n\n### validDate(x)\n\nIf given object is not date throw TypeError in other case return it.\n\n## Date Prototype extensions\n\n### copy(date)\n\nReturns a copy of the date object\n\n### daysInMonth()\n\nReturns number of days of date's month\n\n### floorDay()\n\nSets the date time to 00:00:00.000\n\n### floorMonth()\n\nSets date day to 1 and date time to 00:00:00.000\n\n### floorYear()\n\nSets date month to 0, day to 1 and date time to 00:00:00.000\n\n### format(pattern)\n\nFormats date up to given string. Supported patterns:\n\n* `%Y` - Year with century, 1999, 2003\n* `%y` - Year without century, 99, 03\n* `%m` - Month, 01..12\n* `%d` - Day of the month 01..31\n* `%H` - Hour (24-hour clock), 00..23\n* `%M` - Minute, 00..59\n* `%S` - Second, 00..59\n* `%L` - Milliseconds, 000..999\n\n## Error Constructor extensions\n\n### isError(x)\n\nWhether value is error.  \nIt returns true for all Error instances and Exception host instances (e.g. DOMException)\n\n### validError(x)\n\nIf given object is not error throw TypeError in other case return it.\n\n## Error Prototype extensions\n\n### throw()\n\nThrows error\n\n## Function Constructor extensions\n\nSome of the functions were inspired by [Functional JavaScript](http://osteele.com/sources/javascript/functional/) project by Olivier Steele\n\n### arguments([…args])\n\nReturns arguments object\n\n_arguments.call(…args)  =def  …args_\n\n### context()\n\nReturns context in which function was called\n\n_context.call(x)  =def  x_\n\n### i(x)\n\nIdentity function. Returns first argument\n\n_i(x)  =def  x_\n\n### insert(name, value)\n\nReturns a function that will set _name_ to _value_ on given object\n\n_insert(name, value)(obj)  =def  object\\[name\\] = value_\n\n### invoke(name[, …args])\n\nReturns a function that takes an object as an argument, and applies object's\n_name_ method to arguments.  \n_name_ can be name of the method or method itself.\n\n_invoke(name, …args)(object, …args2)  =def  object\\[name\\]\\(…args, …args2\\)_\n\n### isArguments(x)\n\nWhether value is arguments object\n\n### isFunction(arg)\n\nWether value is instance of function\n\n### k(x)\n\nReturns a constant function that returns pregiven argument\n\n_k(x)(y)  =def  x_\n\n### noop()\n\nNo operation function\n\n### pluck(name)\n\nReturns a function that takes an object, and returns the value of its _name_\nproperty\n\n_pluck(name)(obj)  =def  obj[name]_\n\n### remove(name)\n\nReturns a function that takes an object, and deletes object's _name_ property\n\n_remove(name)(obj)  =def  delete obj[name]_\n\n## Function Prototype extensions\n\nSome of the methods were inspired by [Functional JavaScript](http://osteele.com/sources/javascript/functional/) project by Olivier Steele\n\n### chain([…fns])\n\nApplies the functions in argument-list order.\n\n_f1.chain(f2, f3, f4)(…args)  =def  f4(f3(f2(f1(…arg))))_\n\n### curry([n])\n\nInvoking the function returned by this function only _n_ arguments are passed to the underlying function. If the underlying function is not saturated, the result is a function that passes all its arguments to the underlying function.  \nIf _n_ is not provided then it defaults to context function length\n\n_f.curry(4)(arg1, arg2)(arg3)(arg4)  =def  f(arg1, args2, arg3, arg4)_\n\n### flip()\n\nReturns a function that swaps its first two arguments before passing them to\nthe underlying function.\n\n_f.flip()(a, b, c)  =def  f(b, a, c)_\n\n### lock([…args])\n\nReturns a function that applies the underlying function to _args_, and ignores its own arguments.\n\n_f.lock(…args)(…args2)  =def  f(…args)_\n\n_Named after it's counterpart in Google Closure_\n\n### match()\n\nReturns a function that applies underlying function with first list argument\n\n_f.match()(args)  =def  f.apply(null, args)_\n\n### memoize([, length[, resolvers]])\n\nMemoizes function results, works with any type of input arguments.\n\n\tmemoizedFn = memoize.call(fn);\n\n\tmemoizedFn('foo', 3);\n\tmemoizedFn('foo', 3); // Result taken from cache\n\n#### Arguments length\n\nBy default fixed number of arguments that function takes is assumed (it's\nread from `fn.length` property) this behaviour can be overriden by providing\ncustom _length_ setting e.g.:\n\n\tmemoizedFn = memoize(fn, 2);\n\nor we may pass `false` as length:\n\n\tmemoizeFn = memoize(fn, false);\n\nwhich means that number of arguments is dynamic, and memoize will work with any number of them.\n\n#### Resolvers\n\nIf we expect arguments of certain types it's good to coerce them before doing memoization. We can do that by passing additional resolvers array. Each item is function that would be run on given argument, value returned by function is accepted as coerced value.\n\n\tmemoizeFn = memoize(fn, 2, [String, Boolean]);\n\n#### Cache handling\n\nCollected cache can be cleared. To clear all collected data:\n\n\tmemoizedFn.clearAllCache();\n\nor data for particall call:\n\n\tmemoizedFn.clearCache('foo', true);\n\n### not()\n\nReturns a function that returns boolean negation of value returned by underlying function.\n\n_f.not()(…args)  =def !f(…args)_\n\n### partial([…args])\n\nReturns a function that when called will behave like context function called with initially passed arguments. If more arguments are suplilied, they are appended to initial args.\n\n_f.partial(…args1)(…args2)  =def  f(…args1, …args2)_\n\n### silent()\n\nReturns a function that when called silents any error thrown by underlying function.\nIf underlying function throws error, it is the result fo the function.\n\n_function () { throw err; }.silent()()  ==def  err_\n\n### wrap(fn)\n\nWrap function with other function, it allows to specify before and after behavior, transform return value or prevent original function from being called.\n\nInspired by [Prototype's wrap](http://api.prototypejs.org/language/Function/prototype/wrap/)\n\n## Number Constructor extensions\n\n### isNaN(x)\n\n_In EcmaScript 6th Edition draft_  \n\nWhether value is NaN. Differs from global isNaN that it doesn't do type coercion.\nSee http://wiki.ecmascript.org/doku.php?id=harmony:number.isnan\n\n### isNumber(x)\n\nWhether given value is number\n\n### toInt(x)\n\n_In EcmaScript 6th Edition draft_  \n\nConverts value to integer\n\n### toUint(x)\n\nConverts value to unsigned integer\n\n### toUint32(x)\n\nConverts value to unsigned 32 bit integer. This type is used for array lengths.\nSee: http://www.2ality.com/2012/02/js-integers.html\n\n## Number Prototype extensions\n\n### pad(length[, precision])\n\nPad given number with zeros. Returns string\n\n## Object Constructor extensions\n\n### bindMethods(obj[, context[, source]])\n\nBind all object functions to given scope. If scope is not given then functions are bound to object they're assigned to. This emulates Python's bound instance methods. If source (second argument) is present then all functions from source are binded to scope and assigned to object.\n\nInspired by: http://mochi.github.com/mochikit/doc/html/MochiKit/Base.html#fn-bindmethods\n\n### clear(obj)\n\nRemove all enumerable own properties of the object\n\n### clone(obj)\n\nReturns clone that shares all properties of the object and have same prototype as the object\n\n### compact(obj)\n\nReturns copy of the object with all enumerable properties that have no falsy values\n\n### compare(obj1, obj2)\n\nUniversal cross-type compare function. To be used for e.g. array sort.\n\n### copy(obj[, deep])\n\nReturns copy of the object with all enumerable properties. Additionally nested objects can be copied as well\n\n### count(obj)\n\nCounts number of enumerable own properties on object\n\n### descriptor([mode[, value]])\n### descriptor.gs([mode[, get[, set]]])\n\nDescriptor factory.\n_mode_ is string, through we which we define whether value should be _configurable_, _enumerable_ and/or _writable_, it's accepted as string of tokens, e.g.: `c`, `ce`, `cew`, `cw`, `e`, `ew`, `w`\nIf _mode_ is not provided than `cw` _mode_ is assumed (it's how standard methods are defined on native objects).  \nTo setup descriptor with getter and/or setter use `descriptor.gs`, _mode_ is configured same way as in _value_ version, only difference is that settings for _writable_ attribute are ignored.\n\n### diff(obj1, obj2)\n\nReturns differences between two objects (taking into account only its own enumerable properties).  Returned object is array of three arrays. Each array holds property names:\n\n* 0 - properties that were not present in `obj2`\n* 1 - properties that have different values\n* 2 - properties that were not present in `obj1`\n\n### every(obj, cb[, thisArg[, compareFn]])\n\nAnalogous to Array.prototype.every. Returns true if every key-value pair in this object satisfies the provided testing function.  \nOptionally _compareFn_ can be provided which assures that keys are tested in given order. If provided _compareFn_ is equal to `true`, then order is alphabetical (by key).\n\n### extend(dest[, …src])\n\nExtend _dest_ by enumerable own properties of other objects. Properties found in both objects will be overwritten.\n\n### extendProperties(dest[, …src])\n\nExtend _dest_ by all own properties of other objects. Properties found in both objects will be overwritten (unless they're not configrable and cannot be overwritten).\n\n### filter(obj, cb[, thisArg])\n\nAnalogous to Array.prototype.filter. Returns new object with properites for which _cb_ function returned truthy value.\n\n### flatten(obj)\n\nReturns new object, with flatten properties of input object\n\n_flatten({ a: { b: 1 }, c: { d: 1 } })  =def  { b: 1, d: 1 }_\n\n### forEach(obj, cb[, thisArg[, compareFn]])\n\nAnalogous to Array.prototype.forEach. Calls a function for each key-value pair found in object\nOptionally _compareFn_ can be provided which assures that properties are iterated in given order. If provided _compareFn_ is equal to `true`, then order is alphabetical (by key).\n\n### getPropertyNames()\n\nGet all (not just own) property names of the object\n\n### is(x, y)\n\n_In EcmaScript 6th Edition draft as `is` operator_  \n\nWhether two values are equal, takes into account NaN and -0/+0 cases\n\n### isCallable(x)\n\nWhether object is callable\n\n### isCopy(obj1, obj2)\n\nCompares two objects.  \nObject is considered a copy when its own enumerable properties match own enumerable properties of other object\n\n### isEmpty(obj)\n\nTrue if object doesn't have any own enumerable property\n\n### isList(x)\n\nWhether object is array-like object\n\n### isObject(arg)\n\nWhether value is not primitive\n\n### isPlainObject(arg)\n\nWhether object is plain object, its protototype should be Object.prototype and it cannot be host object.\n\n### keyOf(obj, searchValue)\n\nSearch object for value\n\n### map(obj, cb[, thisArg])\n\nAnalogous to Array.prototype.map. Creates a new object with properties which values are results of calling a provided function on every key-value pair in this object.\n\n### mapKeys(obj, cb[, thisArg])\n\nCreate new object with same values, but remapped keys\n\n### mapToArray(obj[, cb[, thisArg[, compareFn]]])\n\nCreates an array of results of calling a provided function on every key-value pair in this object.  \nOptionally _compareFn_ can be provided which assures that results are added in given order. If provided _compareFn_ is equal to `true`, then order is alphabetical (by key).\n\n### some(obj, cb[, thisArg[, compareFn]])\n\nAnalogous to Array.prototype.some Returns true if any key-value pair satisfies the provided\ntesting function.  \nOptionally _compareFn_ can be provided which assures that keys are tested in given order. If provided _compareFn_ is equal to `true`, then order is alphabetical (by key).\n\n### validCallable(x)\n\nIf given object is not callable throw TypeError in other case return it.\n\n### validValue(x)\n\nThrows error if given value is `null` or `undefined`, otherwise returns `true`.\n\n### values(obj)\n\nReturn array of object own enumerable properties\n\n## RegExp Constructor extensions\n\n### isRegExp(x)\n\nWhether object is regular expression\n\n## String Constructor extensions\n\n### guid()\n\nReturns globally unique string identifier, it starts with a digit and is followed by any characters from _0-9_ and _a-z_ range. Length of string is 9 characters but may increase in future.  \nSimple and friendly implementation for common web application purpose (it's format is different from [official GUID format](http://en.wikipedia.org/wiki/Globally_unique_identifier))\n\n### isString(x)\n\nWhether object is string\n\n## String Prototype extensions\n\n### caseInsensitiveCompare(str)\n\nCase insensitive compare\n\n### contains(searchString[, position])\n\n_In EcmaScript 6th Edition draft_  \nWhether string contains given string.\n\n### dashToCamelCase()\n\nConvert dash separated string to camelCase, e.g. one-two-three -> oneTwoThree\n\n### endsWith(searchString[, endPosition])\n\n_In EcmaScript 6th Edition draft_  \nWhether strings ends with given string\n\n### format(fmap[, thisArg])\n\nFormats given template up to provided map, e.g.:\n\n```javascript\n\"%capital is a capital of %country\".format({\n\tcapital: \"Warsaw\",\n\tcountry: \"Poland\"\n}); // -> \"Warsaw is a capital of Poland\"\n```\nMap may also provide not direct values but functions that resolve value, in that case optional _thisArg_ determines the context in which functions are called.\n\n### indent(str[, count])\n\nIndents each line with provided _str_ (if _count_ given then _str_ is repeated _count_ times).\n\n### last()\n\nReturn last character\n\n### pad(fill[, length])\n\nPad string with _fill_.\nIf _length_ si given than _fill_ is reapated _length_ times.\nIf _length_ is negative then pad is applied from right.\n\n### repeat()\n\nRepeat given string _n_ times\n\n### startsWith(searchString[, position])\n\n_In EcmaScript 6th Edition draft_  \nWhether strings starts with given string\n\n### trimCommonLeft([…strings])\n\nReturns string left trimmed by characters same for all strings\n\n## Math Object extensions\n\n### sign(n)\n\n_In EcmaScript 6th Edition draft_  \nReturns sign of a number value\n\n## Tests [![Build Status](https://secure.travis-ci.org/medikoo/es5-ext.png?branch=master)](https://secure.travis-ci.org/medikoo/es5-ext)\n\n\t$ npm test\n","readmeFilename":"README.md","homepage":"https://github.com/medikoo/es5-ext","_id":"es5-ext@0.8.2","_shasum":"aba8d9e1943a895ac96837a62a39b3f55ecd94ab","_from":"https://registry.npmjs.org/es5-ext/-/es5-ext-0.8.2.tgz","_resolved":"https://registry.npmjs.org/es5-ext/-/es5-ext-0.8.2.tgz"}