Comparing version 0.8.2 to 0.9.0
@@ -6,5 +6,5 @@ // Generate an array built of repeated arguments | ||
var slice = Array.prototype.slice | ||
, value = require('../Object/valid-value') | ||
, value = require('../Object/valid-value'); | ||
module.exports = function (length, fill) { | ||
module.exports = function (length/*, …fill*/) { | ||
var arr, l; | ||
@@ -16,3 +16,3 @@ length = value(length) >>> 0; | ||
arr = (arguments.length < 2) ? [undefined] : | ||
slice.call(arguments, 1, 1 + length); | ||
slice.call(arguments, 1, 1 + length); | ||
@@ -19,0 +19,0 @@ while ((l = arr.length) < length) { |
@@ -5,4 +5,4 @@ 'use strict'; | ||
module.exports = function () { | ||
module.exports = function (/*…items*/) { | ||
return slice.call(arguments); | ||
}; |
'use strict'; | ||
var every = Array.prototype.every | ||
, call = Function.prototype.call | ||
, ois = require('../../Object/is') | ||
@@ -10,3 +9,3 @@ , value = require('../../Object/valid-value') | ||
module.exports = function (list) { | ||
module.exports = function (/*…lists*/) { | ||
var lists, r, l; | ||
@@ -13,0 +12,0 @@ |
@@ -5,4 +5,4 @@ 'use strict'; | ||
module.exports = function (searchElement) { | ||
module.exports = function (searchElement/*, position*/) { | ||
return indexOf.call(this, searchElement, arguments[1]) > -1; | ||
}; |
'use strict'; | ||
var filter = Array.prototype.filter | ||
, forEach = Array.prototype.forEach | ||
, value = require('../../Object/valid-value') | ||
@@ -14,3 +13,3 @@ , copy = require('./copy') | ||
r = copy.call(this); | ||
forEach.call(other, remove.bind(r)); | ||
remove.apply(r, other); | ||
return r; | ||
@@ -17,0 +16,0 @@ } else { |
'use strict'; | ||
var indexOf = Array.prototype.indexOf | ||
, isNaN = require('../../Number/is-nan') | ||
, ois = require('../../Object/is') | ||
, value = require('../../Object/valid-value'); | ||
var indexOf = Array.prototype.indexOf | ||
, numIsNaN = require('../../Number/is-nan') | ||
, ois = require('../../Object/is') | ||
, value = require('../../Object/valid-value'); | ||
module.exports = function (searchElement) { | ||
module.exports = function (searchElement/*, fromIndex*/) { | ||
var i; | ||
if (!isNaN(searchElement) && (searchElement !== 0)) { | ||
if (!numIsNaN(searchElement) && (searchElement !== 0)) { | ||
return indexOf.apply(this, arguments); | ||
@@ -12,0 +12,0 @@ } |
'use strict'; | ||
var lastIndexOf = Array.prototype.lastIndexOf | ||
, isNaN = require('../../Number/is-nan') | ||
, numIsNaN = require('../../Number/is-nan') | ||
, ois = require('../../Object/is') | ||
, value = require('../../Object/valid-value'); | ||
module.exports = function (searchElement) { | ||
module.exports = function (searchElement/*, fromIndex*/) { | ||
var i, fromIndex; | ||
if (!isNaN(searchElement) && (searchElement !== 0)) { | ||
if (!numIsNaN(searchElement) && (searchElement !== 0)) { | ||
return lastIndexOf.apply(this, arguments); | ||
@@ -16,3 +16,3 @@ } | ||
fromIndex = Number(arguments[1]); | ||
fromIndex = isNaN(fromIndex) ? ((this.length >>> 0) - 1) : fromIndex; | ||
fromIndex = numIsNaN(fromIndex) ? ((this.length >>> 0) - 1) : fromIndex; | ||
for (i = fromIndex; i >= 0; --i) { | ||
@@ -19,0 +19,0 @@ if (this.hasOwnProperty(i) && ois(searchElement, this[i])) { |
@@ -5,3 +5,2 @@ 'use strict'; | ||
, push = Array.prototype.push | ||
, call = Function.prototype.call | ||
, value = require('../../Object/valid-value') | ||
@@ -13,3 +12,3 @@ , toArray = require('../from') | ||
module.exports = function (list) { | ||
module.exports = function (/*…lists*/) { | ||
var lists, seen, result; | ||
@@ -16,0 +15,0 @@ if (arguments.length) { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function (query) { | ||
module.exports = function (query/*, thisArg*/) { | ||
var r, self; | ||
@@ -11,0 +11,0 @@ self = Object(value(this)); |
@@ -7,3 +7,3 @@ 'use strict'; | ||
module.exports = function (cb) { | ||
module.exports = function (cb/*, thisArg*/) { | ||
var i, self, thisArg; | ||
@@ -10,0 +10,0 @@ |
@@ -11,3 +11,3 @@ // Inspired by Underscore's groupBy: | ||
module.exports = function (cb) { | ||
module.exports = function (cb/*, thisArg*/) { | ||
var self, r; | ||
@@ -14,0 +14,0 @@ self = Object(value(this)); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function (value) { | ||
module.exports = function (value/*, fromIndex*/) { | ||
var r = [], i, fromIndex = arguments[1]; | ||
@@ -8,0 +8,0 @@ while ((i = indexOf.call(this, value, fromIndex)) !== -1) { |
@@ -6,3 +6,2 @@ 'use strict'; | ||
, slice = Array.prototype.slice | ||
, call = Function.prototype.call | ||
, value = require('../../Object/valid-value') | ||
@@ -12,3 +11,3 @@ , contains = require('./contains') | ||
module.exports = function (list) { | ||
module.exports = function (/*…list*/) { | ||
var lists; | ||
@@ -15,0 +14,0 @@ if (arguments.length) { |
'use strict'; | ||
var indexOf = require('./e-index-of') | ||
, splice = Array.prototype.splice; | ||
var forEach = Array.prototype.forEach | ||
, splice = Array.prototype.splice | ||
, indexOf = require('./e-index-of'); | ||
module.exports = function (item) { | ||
var index = indexOf.call(this, item); | ||
if (index !== -1) { | ||
splice.call(this, index, 1); | ||
} | ||
module.exports = function (/*item*/) { | ||
forEach.call(arguments, function (item) { | ||
var index = indexOf.call(this, item); | ||
if (index !== -1) { | ||
splice.call(this, index, 1); | ||
} | ||
}, this); | ||
}; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
module.exports = function (cb) { | ||
module.exports = function (cb/*, thisArg*/) { | ||
var i, self, thisArg; | ||
@@ -10,0 +10,0 @@ self = Object(value(this)); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
, id = toString.call(new Boolean(true)); | ||
, id = toString.call(true); | ||
@@ -8,0 +8,0 @@ module.exports = function (x) { |
@@ -6,4 +6,2 @@ // Export all modules. | ||
module.exports = { | ||
arguments: require('./arguments'), | ||
context: require('./context'), | ||
i: require('./i'), | ||
@@ -10,0 +8,0 @@ insert: require('./insert'), |
@@ -6,9 +6,8 @@ 'use strict'; | ||
, isCallable = require('../Object/is-callable') | ||
, value = require('../Object/valid-value') | ||
, memoize = require('./prototype/memoize'); | ||
, value = require('../Object/valid-value'); | ||
module.exports = memoize.call(function (name) { | ||
module.exports = function (name/*, …args*/) { | ||
var args, isFn; | ||
args = slice.call(arguments, 1) | ||
args = slice.call(arguments, 1); | ||
if (!(isFn = isCallable(name))) { | ||
@@ -22,2 +21,2 @@ name = String(name); | ||
}; | ||
}, false); | ||
}; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
, id = toString.call(require('./arguments')()); | ||
, id = toString.call((function () { return arguments; }())); | ||
@@ -8,0 +8,0 @@ module.exports = function (x) { |
'use strict'; | ||
var value = require('../Object/valid-value') | ||
, memoize = require('./prototype/memoize'); | ||
var value = require('../Object/valid-value'); | ||
module.exports = memoize.call(function (name) { | ||
module.exports = function (name) { | ||
return function (o) { | ||
return value(o)[name]; | ||
}; | ||
}, 1, [function (name) { | ||
return String(name); | ||
}]); | ||
}; |
@@ -6,16 +6,16 @@ 'use strict'; | ||
, callable = require('../../Object/valid-callable') | ||
, partial = require('./partial') | ||
, hold = function hold(fn, n, args) { | ||
args = args.concat(slice.call(arguments, 3)).slice(0, n); | ||
return args.length === n ? apply.call(fn, this, args) : | ||
hold.partial(fn, n, args); | ||
, curry = function self(fn, n, inputArgs) { | ||
return function () { | ||
var args = inputArgs ? | ||
inputArgs.concat(slice.call(arguments, 0, n - inputArgs.length)) : | ||
slice.call(arguments, 0, n); | ||
return (args.length === n) ? apply.call(fn, this, args) : | ||
self(fn, n, args); | ||
}; | ||
}; | ||
hold.partial = partial; | ||
module.exports = function (n) { | ||
callable(this); | ||
return hold.partial(this, | ||
isNaN(n) ? this.length : Number(n), []); | ||
module.exports = function (/*n*/) { | ||
var n = arguments[0]; | ||
return curry(callable(this), isNaN(n) ? this.length : Number(n)); | ||
}; |
@@ -6,6 +6,4 @@ 'use strict'; | ||
curry: require('./curry'), | ||
flip: require('./flip'), | ||
lock: require('./lock'), | ||
match: require('./match'), | ||
memoize: require('./memoize'), | ||
not: require('./not'), | ||
@@ -12,0 +10,0 @@ partial: require('./partial'), |
@@ -6,3 +6,3 @@ 'use strict'; | ||
module.exports = function () { | ||
module.exports = function (/*…args*/) { | ||
var fn = callable(this) | ||
@@ -9,0 +9,0 @@ , args = arguments; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
module.exports = function () { | ||
module.exports = function (/*…args*/) { | ||
var fn = callable(this) | ||
@@ -10,0 +10,0 @@ , args = toArray(arguments); |
'use strict'; | ||
var value = require('../Object/valid-value') | ||
, memoize = require('./prototype/memoize'); | ||
var value = require('../Object/valid-value'); | ||
module.exports = memoize.call(function (name) { | ||
module.exports = function (name) { | ||
return function (obj) { | ||
delete value(obj)[name]; | ||
}; | ||
}, [function (name) { | ||
return String(name); | ||
}]); | ||
}; |
@@ -1,2 +0,2 @@ | ||
'use strict' | ||
'use strict'; | ||
@@ -3,0 +3,0 @@ module.exports = function (value) { |
'use strict'; | ||
module.exports = function (value) { | ||
return (value !== value); | ||
return (value !== value); //jslint: skip | ||
}; |
@@ -7,6 +7,6 @@ 'use strict'; | ||
module.exports = function (length, precision) { | ||
var fn; | ||
module.exports = function (length/*, precision*/) { | ||
var precision; | ||
length = toInt(length); | ||
precision = toInt(precision); | ||
precision = toInt(arguments[1]); | ||
@@ -13,0 +13,0 @@ return pad.call(precision ? toFixed.call(this, precision) : this, |
@@ -21,3 +21,3 @@ // Internal method, used by iteration functions. | ||
if (compareFn) { | ||
list.sort(isCallable(compareFn) ? compareFn : undefined); | ||
list.sort(isCallable(compareFn) ? compareFn.bind(obj) : undefined); | ||
} | ||
@@ -24,0 +24,0 @@ return list[method](function (key, index) { |
'use strict'; | ||
var keys = Object.keys | ||
, isString = require('../String/is-string') | ||
, strCompare = require('../String/prototype/case-insensitive-compare') | ||
var strCompare = require('../String/prototype/case-insensitive-compare') | ||
, isObject = require('./is-object') | ||
@@ -35,3 +33,3 @@ | ||
b = resolve(b); | ||
if (a == b) { | ||
if (a == b) { //jslint: skip | ||
return typeMap[typeof a] - typeMap[typeof b]; | ||
@@ -38,0 +36,0 @@ } else if (a == null) { |
@@ -25,7 +25,7 @@ 'use strict'; | ||
module.exports = function (obj, deep) { | ||
module.exports = function (obj/*, deep*/) { | ||
var copy; | ||
if ((copy = Object(value(obj))) === obj) { | ||
copy = extend({}, obj); | ||
if (deep) { | ||
if (arguments[1]) { | ||
recursive(copy, obj, [[obj], [copy]]); | ||
@@ -32,0 +32,0 @@ } |
@@ -20,3 +20,3 @@ 'use strict'; | ||
module.exports = function (dest, src) { | ||
module.exports = function (dest/*, …src*/) { | ||
var properties; | ||
@@ -23,0 +23,0 @@ forEach.call(arguments, value); |
@@ -15,3 +15,3 @@ 'use strict'; | ||
module.exports = function (dest, src) { | ||
module.exports = function (dest/*, …src*/) { | ||
forEach.call(arguments, value); | ||
@@ -18,0 +18,0 @@ slice.call(arguments, 1).forEach(extend, dest); |
@@ -5,4 +5,4 @@ 'use strict'; | ||
module.exports = function (obj, cb, thisArg) { | ||
var o = {}; | ||
module.exports = function (obj, cb/*, thisArg*/) { | ||
var o = {}, thisArg = arguments[2]; | ||
forEach(obj, function (value, key) { | ||
@@ -9,0 +9,0 @@ if (cb.call(thisArg, value, key)) { |
'use strict'; | ||
module.exports = { | ||
bindMethods: require('./bind-methods'), | ||
clear: require('./clear'), | ||
clone: require('./clone'), | ||
compact: require('./compact'), | ||
@@ -32,2 +30,3 @@ compare: require('./compare'), | ||
some: require('./some'), | ||
toPlainObject: require('./to-plain-object'), | ||
validCallable: require('./valid-callable'), | ||
@@ -34,0 +33,0 @@ validValue: require('./valid-value'), |
'use strict'; | ||
var keys = Object.keys | ||
, value = require('./valid-value'); | ||
var keys = Object.keys | ||
, toUint = require('../Number/to-uint') | ||
, ois = require('./is') | ||
module.exports = function (a, b) { | ||
var aKeys; | ||
a = Object(value(a)); | ||
if (b == null) { | ||
, isCopy; | ||
isCopy = function (a, b, depth, cache) { | ||
var aKeys, bKeys, index, index2; | ||
if (((typeof a) !== (typeof b)) || (String(a) !== String(b))) { | ||
return false; | ||
} | ||
b = Object(b); | ||
if (a === b) { | ||
if (!a || (typeof a !== 'object')) { | ||
return true; | ||
} | ||
return ((aKeys = keys(a)).length === keys(b).length) && | ||
aKeys.every(function (name) { | ||
return b.propertyIsEnumerable(name) && (a[name] === b[name]); | ||
}, a); | ||
aKeys = keys(a); | ||
bKeys = keys(b); | ||
if (aKeys.length !== bKeys.length) { | ||
return false; | ||
} | ||
if (cache) { | ||
// Prevent infinite recursion | ||
index = cache.a.indexOf(a); | ||
if (index === -1) { | ||
index = cache.a.indexOf(b); | ||
if (index === -1) { | ||
cache.a.push(a); | ||
cache.b.push([b]); | ||
} else if (cache.b[index].indexOf(a) !== -1) { | ||
return true; | ||
} else { | ||
cache.b[index].push(a); | ||
} | ||
} else if ((cache.b[index].indexOf(b) !== -1) || | ||
(((index2 = cache.a.indexOf(b)) !== -1) && | ||
(cache.b[index2].indexOf(a) !== -1))) { | ||
return true; | ||
} else { | ||
cache.b[index].push(b); | ||
} | ||
} | ||
return aKeys.every(function (name) { | ||
if (!b.propertyIsEnumerable(name)) { | ||
return false; | ||
} | ||
if (ois(a[name], b[name])) { | ||
return true; | ||
} | ||
return depth ? isCopy(a[name], b[name], depth - 1, cache) : false; | ||
}); | ||
}; | ||
module.exports = function (a, b/*, depth*/) { | ||
var depth, cache; | ||
if (ois(a, b)) { | ||
return true; | ||
} | ||
depth = arguments[2]; | ||
depth = isNaN(depth) ? 0 : toUint(depth); | ||
if (!isFinite(depth)) { | ||
cache = { a: [], b: [] }; | ||
} | ||
return isCopy(a, b, depth, !isFinite(depth) && { a: [], b: [] }); | ||
}; |
@@ -8,3 +8,3 @@ 'use strict'; | ||
value(obj); | ||
for (i in obj) { | ||
for (i in obj) { //jslint: skip | ||
if (obj.propertyIsEnumerable(i)) { | ||
@@ -11,0 +11,0 @@ return false; |
'use strict'; | ||
var map = { function: true, object: true }; | ||
var map = { 'function': true, 'object': true }; | ||
@@ -5,0 +5,0 @@ module.exports = function (x) { |
@@ -10,5 +10,8 @@ 'use strict'; | ||
module.exports = function (value) { | ||
return (value && (typeof value === 'object') && | ||
(getPrototypeOf(value) === prototype) && (toString.call(value) === id)) || | ||
false; | ||
var proto; | ||
if (!value || (typeof value !== 'object') || (toString.call(value) !== id)) { | ||
return false; | ||
} | ||
proto = getPrototypeOf(value); | ||
return (proto === prototype) || (getPrototypeOf(proto) === null); | ||
}; |
@@ -8,4 +8,4 @@ // Implementation credits go to: | ||
return (x === y) ? | ||
((x !== 0) || ((1 / x) === (1 / y))) : | ||
((x !== x) && (y !== y)); | ||
((x !== 0) || ((1 / x) === (1 / y))) : | ||
((x !== x) && (y !== y)); //jslint: skip | ||
}; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
module.exports = function (obj, cb) { | ||
module.exports = function (obj, cb/*, thisArg*/) { | ||
var o = {}, thisArg = arguments[2]; | ||
@@ -8,0 +8,0 @@ forEach(obj, function (value, key) { |
@@ -12,3 +12,3 @@ 'use strict'; | ||
module.exports = function (obj, cb) { | ||
module.exports = function (obj, cb/*, thisArg*/) { | ||
var a = [], thisArg = arguments[2]; | ||
@@ -15,0 +15,0 @@ cb = (cb == null) ? defaultCb : callable(cb); |
@@ -5,8 +5,8 @@ 'use strict'; | ||
module.exports = function (obj, cb) { | ||
var o = {}; | ||
module.exports = function (obj, cb/*, thisArg*/) { | ||
var o = {}, thisArg = arguments[2]; | ||
forEach(obj, function (value, key) { | ||
o[key] = cb.call(this, value, key, obj); | ||
}, arguments[2]); | ||
o[key] = cb.call(thisArg, value, key, obj); | ||
}); | ||
return o; | ||
}; |
@@ -6,4 +6,4 @@ 'use strict'; | ||
, get = function (key) { | ||
return this[key]; | ||
}; | ||
return this[key]; | ||
}; | ||
@@ -10,0 +10,0 @@ module.exports = function (obj) { |
'use strict'; | ||
var freeze = Object.freeze | ||
var keywords, future, futureStrict, all; | ||
, keywords, future, futureStrict, all; | ||
// 7.6.1.1 Keywords | ||
keywords = freeze(['break', 'case', 'catch', 'continue', 'debugger', 'default', 'delete', 'do', | ||
'else', 'finally', 'for', 'function', 'if', 'in', 'instanceof', 'new', | ||
'return', 'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while', | ||
'with']); | ||
keywords = ['break', 'case', 'catch', 'continue', 'debugger', 'default', | ||
'delete', 'do', 'else', 'finally', 'for', 'function', 'if', 'in', | ||
'instanceof', 'new', 'return', 'switch', 'this', 'throw', 'try', 'typeof', | ||
'var', 'void', 'while', 'with']; | ||
// 7.6.1.2 Future Reserved Words | ||
future = freeze(['class', 'const', 'enum', 'exports', 'extends', 'import', 'super']) | ||
future = ['class', 'const', 'enum', 'exports', 'extends', 'import', 'super']; | ||
// Future Reserved Words (only in strict mode) | ||
futureStrict = freeze(['implements', 'interface', 'let', 'package', 'private', 'protected', 'public', | ||
'static', 'yield']); | ||
futureStrict = ['implements', 'interface', 'let', 'package', 'private', | ||
'protected', 'public', 'static', 'yield']; | ||
@@ -24,2 +22,1 @@ all = module.exports = keywords.concat(future, futureStrict); | ||
all.futureStrict = futureStrict; | ||
freeze(all); |
'use strict'; | ||
module.exports = { | ||
guid: require('./guid'), | ||
isString: require('./is-string'), | ||
prototype: require('./prototype') | ||
}; |
@@ -8,4 +8,4 @@ 'use strict'; | ||
module.exports = function (x) { | ||
return (typeof x === 'string') || (x && (typeof x == 'object') && | ||
return (typeof x === 'string') || (x && (typeof x === 'object') && | ||
((x instanceof String) || (toString.call(x) === id))) || false; | ||
}; |
@@ -5,4 +5,4 @@ 'use strict'; | ||
module.exports = function (searchString) { | ||
module.exports = function (searchString/*, position*/) { | ||
return indexOf.call(this, searchString, arguments[1]) > -1; | ||
}; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
module.exports = function (searchString) { | ||
module.exports = function (searchString/*, endPosition*/) { | ||
var self, start, endPos; | ||
@@ -13,5 +13,5 @@ self = String(value(this)); | ||
endPos = arguments[1]; | ||
start = ((endPos == null) ? self.length : min(toUint(endPos), self.length)) | ||
- searchString.length; | ||
start = ((endPos == null) ? self.length : | ||
min(toUint(endPos), self.length)) - searchString.length; | ||
return (start < 0) ? false : (self.indexOf(searchString, start) === start); | ||
}; |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function (fmap) { | ||
module.exports = function (fmap/*, thisArg*/) { | ||
var t, fn, thisArg = arguments[1]; | ||
@@ -22,6 +22,6 @@ value(this); | ||
} | ||
return fn ? (isCallable(fn) ? call.call(fn, thisArg) : fn) | ||
+ token.slice(t.length) : match; | ||
return fn ? (isCallable(fn) ? | ||
call.call(fn, thisArg) : fn) + token.slice(t.length) : match; | ||
} | ||
}); | ||
}; |
@@ -8,5 +8,5 @@ 'use strict'; | ||
module.exports = function (indent, count) { | ||
indent = repeat.call(String(indent), count); | ||
module.exports = function (indent/*, count*/) { | ||
indent = repeat.call(String(indent), arguments[1]); | ||
return indent + replace.call(this, re, '$1' + indent + '$2'); | ||
}; |
'use strict'; | ||
module.exports = { | ||
camelToHyphen: require('./camel-to-hyphen'), | ||
caseInsensitiveCompare: require('./case-insensitive-compare'), | ||
contains: require('./contains'), | ||
dashToCamelCase: require('./dash-to-camel-case'), | ||
hyphenToCamel: require('./hyphen-to-camel'), | ||
endsWith: require('./ends-with'), | ||
@@ -8,0 +9,0 @@ format: require('./format'), |
'use strict'; | ||
var abs = Math.abs | ||
, max = Math.max | ||
, max = Math.max | ||
, toInt = require('../../Number/to-int') | ||
@@ -9,5 +9,7 @@ , value = require('../../Object/valid-value') | ||
module.exports = function (fill, length) { | ||
module.exports = function (fill/*, length*/) { | ||
var self = String(value(this)) | ||
, sLength = self.length; | ||
, sLength = self.length | ||
, length = arguments[1]; | ||
length = isNaN(length) ? 1 : toInt(length); | ||
@@ -19,4 +21,4 @@ fill = repeat.call(String(fill), abs(length)); | ||
return self + (((sLength + length) >= 0) ? '' : | ||
fill.slice(length + sLength)); | ||
fill.slice(length + sLength)); | ||
} | ||
}; |
@@ -6,6 +6,7 @@ // Not rocket science but taken from: | ||
var value = require('../../Object/valid-value'); | ||
var value = require('../../Object/valid-value') | ||
, toUint = require('../../Number/to-uint'); | ||
module.exports = function (n) { | ||
return new Array((isNaN(n) ? 1 : Number(n)) + 1).join(String(value(this))); | ||
return new Array((isNaN(n) ? 1 : toUint(n)) + 1).join(String(value(this))); | ||
}; |
@@ -6,5 +6,5 @@ 'use strict'; | ||
module.exports = function (searchString) { | ||
module.exports = function (searchString/*, position*/) { | ||
var start = toUint(arguments[1]); | ||
return (indexOf.call(this, searchString, start) === start); | ||
}; |
@@ -8,5 +8,5 @@ 'use strict'; | ||
module.exports = function (str) { | ||
module.exports = function (/*…str*/) { | ||
var self = String(value(this)); | ||
return self.slice(find.apply(self, map.call(arguments, toString))); | ||
}; |
{ | ||
"name": "es5-ext", | ||
"version": "0.8.2", | ||
"version": "0.9.0", | ||
"description": "ECMAScript5 extensions", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
132
README.md
@@ -11,6 +11,8 @@ # es5-ext - ECMAScript5 extensions | ||
To use it with node.js: | ||
### NPM: | ||
$ npm install es5-ext | ||
### Browser: | ||
For browser, you can create custom toolset with help of | ||
@@ -24,3 +26,3 @@ [modules-webmake](https://github.com/medikoo/modules-webmake) | ||
Function.prototype.curry = require('es5-ext/lib/Function/prototype/curry'); | ||
Function.prototype.partial = require('es5-ext/lib/Function/prototype/partial'); | ||
@@ -31,7 +33,5 @@ Array.prototype.flatten = require('es5-ext/lib/Array/prototype/flatten'); | ||
However, extending native prototypes is controversial and in general discouraged, | ||
most will agree that __it's ok only if we own the context__ (see | ||
If you decide not to extend native prototypes, which in many cases is good idea (see | ||
[extending-javascript-natives](http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/) | ||
for more views on that matter). | ||
So when you don't want to extend native prototypes you can use methods as | ||
for more views on that matter), you can use methods as | ||
functions: | ||
@@ -42,3 +42,3 @@ | ||
util.curry = call.bind(require('es5-ext/lib/Function/prototype/curry')); | ||
util.partial = call.bind(require('es5-ext/lib/Function/prototype/partial')); | ||
@@ -58,3 +58,3 @@ util.flatten = call.bind(require('es5-ext/lib/Array/prototype/flatten')); | ||
API 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_). | ||
API doesn't provide any methods for `Object.prototype` (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_). | ||
@@ -76,6 +76,2 @@ # API | ||
### generate([length[, …fill]]) | ||
Generate an array of pregiven _length_ built of repeated arguments. | ||
### from(x) | ||
@@ -86,2 +82,6 @@ | ||
### generate([length[, …fill]]) | ||
Generate an array of pregiven _length_ built of repeated arguments. | ||
### of([…items]) | ||
@@ -259,14 +259,2 @@ | ||
### arguments([…args]) | ||
Returns arguments object | ||
_arguments.call(…args) =def …args_ | ||
### context() | ||
Returns context in which function was called | ||
_context.call(x) =def x_ | ||
### i(x) | ||
@@ -340,9 +328,2 @@ | ||
### flip() | ||
Returns a function that swaps its first two arguments before passing them to | ||
the underlying function. | ||
_f.flip()(a, b, c) =def f(b, a, c)_ | ||
### lock([…args]) | ||
@@ -362,41 +343,2 @@ | ||
### memoize([, length[, resolvers]]) | ||
Memoizes function results, works with any type of input arguments. | ||
memoizedFn = memoize.call(fn); | ||
memoizedFn('foo', 3); | ||
memoizedFn('foo', 3); // Result taken from cache | ||
#### Arguments length | ||
By default fixed number of arguments that function takes is assumed (it's | ||
read from `fn.length` property) this behaviour can be overriden by providing | ||
custom _length_ setting e.g.: | ||
memoizedFn = memoize(fn, 2); | ||
or we may pass `false` as length: | ||
memoizeFn = memoize(fn, false); | ||
which means that number of arguments is dynamic, and memoize will work with any number of them. | ||
#### Resolvers | ||
If 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. | ||
memoizeFn = memoize(fn, 2, [String, Boolean]); | ||
#### Cache handling | ||
Collected cache can be cleared. To clear all collected data: | ||
memoizedFn.clearAllCache(); | ||
or data for particall call: | ||
memoizedFn.clearCache('foo', true); | ||
### not() | ||
@@ -463,8 +405,2 @@ | ||
### bindMethods(obj[, context[, source]]) | ||
Bind 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. | ||
Inspired by: http://mochi.github.com/mochikit/doc/html/MochiKit/Base.html#fn-bindmethods | ||
### clear(obj) | ||
@@ -474,6 +410,2 @@ | ||
### clone(obj) | ||
Returns clone that shares all properties of the object and have same prototype as the object | ||
### compact(obj) | ||
@@ -553,7 +485,13 @@ | ||
### isCopy(obj1, obj2) | ||
### isCopy(x, y[, depth]) | ||
Compares two objects. | ||
Object is considered a copy when its own enumerable properties match own enumerable properties of other object | ||
Two values are considered a copy of same value when they meet following rules: | ||
1. Are of same type (`typeof` check) | ||
2. Have same string representation | ||
3. (Objects only) Own enumerable properties of first object match own | ||
enumerable properties of other object. Optionally depth can be provided at which relaxed comparision rules need to be applied. This allows deep comparision of different objects. | ||
Objects can contain self references, algorithm is aware of possible infinite loop traps and won't into them. | ||
### isEmpty(obj) | ||
@@ -598,2 +536,7 @@ | ||
### toPlainObject(x) | ||
Returns plain object build from x object and it's prototypes enumerable properties | ||
If x is not given, then empty object is returned. | ||
### validCallable(x) | ||
@@ -605,3 +548,3 @@ | ||
Throws error if given value is `null` or `undefined`, otherwise returns `true`. | ||
Throws error if given value is `null` or `undefined`, otherwise returns value. | ||
@@ -620,7 +563,2 @@ ### values(obj) | ||
### guid() | ||
Returns 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. | ||
Simple 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)) | ||
### isString(x) | ||
@@ -632,2 +570,7 @@ | ||
### camelToHyphen() | ||
Convert camelCase string to hyphen separated, e.g. one-two-three -> oneTwoThree. | ||
Useful when converting names from js property convention into filename convention. | ||
### caseInsensitiveCompare(str) | ||
@@ -642,6 +585,2 @@ | ||
### dashToCamelCase() | ||
Convert dash separated string to camelCase, e.g. one-two-three -> oneTwoThree | ||
### endsWith(searchString[, endPosition]) | ||
@@ -664,2 +603,7 @@ | ||
### hyphenToCamel() | ||
Convert hyphen separated string to camelCase, e.g. one-two-three -> oneTwoThree. | ||
Useful when converting names from filename convention to js property name convention. | ||
### indent(str[, count]) | ||
@@ -679,3 +623,3 @@ | ||
### repeat() | ||
### repeat(n) | ||
@@ -682,0 +626,0 @@ Repeat given string _n_ times |
'use strict'; | ||
module.exports = function (t, a) { | ||
var o = [1, 2, 3], r; | ||
var o = [1, 2, 3]; | ||
a(t(o), o, "Array"); | ||
a.deep(t('12r3v'), ['1', '2', 'r', '3', 'v'], "String"); | ||
a.deep(t((function (x) { return arguments; }(3, o, 'raz'))), | ||
a.deep(t((function () { return arguments; }(3, o, 'raz'))), | ||
[3, o, 'raz'], "Arguments"); | ||
a.deep(t((function (x) { return arguments; }(3))), [3], | ||
a.deep(t((function () { return arguments; }(3))), [3], | ||
"Arguments with one numeric value"); | ||
@@ -11,0 +11,0 @@ a(t("12345", 2, 3).length, 5, "Extra arguments does not affect result"); |
@@ -10,2 +10,2 @@ 'use strict'; | ||
"Many arguments"); | ||
} | ||
}; |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function (t, a) { | ||
var arr, fn, search; | ||
var arr; | ||
arr = [2, 5, 5, 8, 34, 67, 98, 345, 678]; | ||
@@ -11,0 +11,0 @@ |
'use strict'; | ||
var o = [1, 2, [3, 4, [5, 6], 7, 8], 9, 10]; | ||
module.exports = { | ||
@@ -6,0 +4,0 @@ __generic: function (t, a) { |
@@ -9,3 +9,3 @@ 'use strict'; | ||
"": function (t, a) { | ||
var x = {}, y = {}, z = {}; | ||
var x = {}, y = {}; | ||
@@ -12,0 +12,0 @@ a.deep(t.call([x, y]), [x, y], "No arguments"); |
@@ -13,3 +13,3 @@ 'use strict'; | ||
count = -1; | ||
a(t.call(this, function (value, i, scope) { | ||
a(t.call(this, function () { | ||
return ++count ? o : null; | ||
@@ -16,0 +16,0 @@ }, this), this[1], "Truthy result"); |
@@ -18,3 +18,3 @@ 'use strict'; | ||
r = t.call([2, 3, 3, 4, 5, 6, 7, 7, 23, 45, 34, 56], | ||
function (v, i, scope) { | ||
function (v) { | ||
return v % 2 ? 'odd' : 'even'; | ||
@@ -21,0 +21,0 @@ }); |
@@ -11,2 +11,5 @@ 'use strict'; | ||
a.deep(x, [9, z, 'foo'], "Primitive"); | ||
x = [9, z, 5, y, 'foo']; | ||
t.call(x, z, 5, 'foo'); | ||
a.deep(x, [9, y], "More than one argument"); | ||
}; |
@@ -10,4 +10,4 @@ 'use strict'; | ||
a.throws(function () { | ||
t(new Number(20)); | ||
t({ valueOf: function () { return 20; } }); | ||
}, "Number object"); | ||
}; |
@@ -10,4 +10,7 @@ 'use strict'; | ||
module.exports = function (t, a) { | ||
var x, y = {}; | ||
a.deep(t.call(f, 0, 1, 2)(3), [], "0 arguments"); | ||
a.deep(t.call(f, 5, {})(1, 2)(3, 4)(5, 6), [1, 2, 3, 4, 5], "Many arguments"); | ||
x = t.call(f, 5, {}); | ||
a.deep(x(1, 2)(3, 4)(5, 6), [1, 2, 3, 4, 5], "Many arguments"); | ||
a.deep(x(8, 3)(y, 45)('raz', 6), [8, 3, y, 45, 'raz'], "Many arguments #2"); | ||
}; |
'use strict'; | ||
module.exports = function (t, a) { | ||
a(t.call(function (a, b, c) { | ||
a(t.call(function () { | ||
return arguments.length; | ||
})(1, 2, 3), 0); | ||
}; |
@@ -7,3 +7,3 @@ 'use strict'; | ||
f = function (a, b, c) { | ||
f = function () { | ||
return toArray(arguments); | ||
@@ -10,0 +10,0 @@ }; |
'use strict'; | ||
var noop = require('../../../lib/Function/noop') | ||
, toArray = require('../../../lib/Array/from'); | ||
module.exports = function (t, a) { | ||
@@ -7,0 +4,0 @@ var called = false, original, x = {}, y = {}, z = {}, w = {}, wrap; |
'use strict'; | ||
module.exports = function (t, a) { | ||
var x = {}, y = {}, z = {}, r; | ||
var x = {}, y = {}, r; | ||
@@ -6,0 +6,0 @@ r = t({ foo: 'bar', x: x, raz: 'dwa', y: y }, |
'use strict'; | ||
module.exports = function (t, a) { | ||
var o, o1, o2, o3, x, y = {}, z = {}; | ||
var o, o1, o2, x, y = {}, z = {}; | ||
o = { inherited: true }; | ||
@@ -11,3 +11,3 @@ o1 = Object.create(o); | ||
o2 = Object.defineProperties({}, { nonremovable: { value: y }}); | ||
o2 = Object.defineProperties({}, { nonremovable: { value: y } }); | ||
o2.other = 'other'; | ||
@@ -41,3 +41,3 @@ | ||
a(x.nonremovable,'raz', "Ignored non configurable"); | ||
a(x.nonremovable, 'raz', "Ignored non configurable"); | ||
a(x.other, 'other', "Other"); | ||
@@ -44,0 +44,0 @@ |
@@ -7,3 +7,3 @@ 'use strict'; | ||
a.deep(t({}, o1, o2), {a: 1, b: 3, c: 4 }, "Multi argument"); | ||
a.deep(t({}, o1, o2), { a: 1, b: 3, c: 4 }, "Multi argument"); | ||
@@ -10,0 +10,0 @@ t(o1, o2); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
a.deep(t({ 1: 1, 2: 2, 3: 3, 4: 4 }, | ||
function (value, key) { return !!(value % 2); }), { 1: 1, 3: 3 }); | ||
function (value) { return Boolean(value % 2); }), { 1: 1, 3: 3 }); | ||
}; |
'use strict'; | ||
module.exports = function (t, a) { | ||
var x, y; | ||
a(t(null, null), true, "null vs null"); | ||
a(t({}, null), false, "Object vs null"); | ||
a(t(undefined, null), false, "Undefined vs null"); | ||
a(t({ 1: 1, 2: 2, 3: 3 }, { 1: 1, 2: 2, 3: 3 }), true, "Same"); | ||
@@ -11,2 +17,49 @@ a(t({ 1: 1, 2: 2, 3: 3 }, { 1: 1, 2: 2, 3: 4 }), false, | ||
"Property only in target"); | ||
a(t("raz", "dwa"), false, "String: diff"); | ||
a(t("raz", "raz"), true, "String: same"); | ||
a(t("32", 32), false, "String & Number"); | ||
a(t("raz", new String("raz")), false, "String & String object"); | ||
a(t([1, 'raz', true], [1, 'raz', true]), true, "Array: same"); | ||
a(t([1, 'raz', undefined], [1, 'raz']), false, "Array: diff"); | ||
x = { foo: { bar: { mar: {} } } }; | ||
y = { foo: { bar: { mar: {} } } }; | ||
a(t(x, y, Infinity), true, "Object: deep"); | ||
a(t(x, y, 3), true, "Object: deep limited"); | ||
a(t(x, y, 2), false, "Object: deep shallow"); | ||
a(t({ foo: { bar: { mar: 'foo' } } }, { foo: { bar: { mar: {} } } }, | ||
Infinity), false, "Object: deep"); | ||
x = { foo: { bar: { mar: {} } } }; | ||
x.rec = { foo: x }; | ||
y = { foo: { bar: { mar: {} } } }; | ||
y.rec = { foo: x }; | ||
a(t(x, y, Infinity), true, | ||
"Object: Infinite Recursion: Same #1"); | ||
x.rec.foo = y; | ||
a(t(x, y, Infinity), true, | ||
"Object: Infinite Recursion: Same #2"); | ||
x.rec.foo = x; | ||
y.rec.foo = y; | ||
a(t(x, y, Infinity), true, | ||
"Object: Infinite Recursion: Same #3"); | ||
y.foo.bar.mar = 'raz'; | ||
a(t(x, y, Infinity), false, | ||
"Object: Infinite Recursion: Diff"); | ||
a(t(function () { return 'raz'; }, function () { return 'raz'; }), true, | ||
"Function: same"); | ||
a(t(function () { return 'raz'; }, function () { return 'dwa'; }), false, | ||
"Function: diff"); | ||
a(t(/raz/, /raz/), true, "Regexp: same"); | ||
a(t(/raz/, /dwa/), false, "Regexp: diff"); | ||
}; |
@@ -10,5 +10,5 @@ 'use strict'; | ||
a(t('string'), false, "Primitive is not plain object"); | ||
a(t(function (t, a) {}), false, "Function is not plain object"); | ||
a(t(function () {}), false, "Function is not plain object"); | ||
a(t(Object.create({})), false, | ||
"Object whose prototype is not Object.prototype is not plain object"); | ||
}; |
@@ -12,5 +12,5 @@ 'use strict'; | ||
t(o).sort().forEach(function (item, index) { | ||
t(o).sort().forEach(function (item) { | ||
a.deep(item, [item[0], o[item[0]]], "Default"); | ||
}); | ||
}; |
'use strict'; | ||
var isNaN = require('../../lib/Number/is-nan'); | ||
var numIsNaN = require('../../lib/Number/is-nan'); | ||
@@ -10,3 +10,3 @@ module.exports = function (t, a) { | ||
a(t(''), '', "''"); | ||
a(isNaN(t(NaN)), true, "NaN"); | ||
a(numIsNaN(t(NaN)), true, "NaN"); | ||
a(t(x = {}), x, "{}"); | ||
@@ -13,0 +13,0 @@ |
'use strict'; | ||
module.exports = function (t, a) { | ||
var o, x = {}, y = {}; | ||
a(t.call('raz', ''), true, "Empty"); | ||
@@ -7,0 +5,0 @@ a(t.call('', ''), true, "Both Empty"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124273
249
2965
627