Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "core-js", | ||
"description": "Standard library", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"repository": { | ||
@@ -11,8 +11,8 @@ "type": "git", | ||
"devDependencies": { | ||
"LiveScript": "*", | ||
"grunt": "*", | ||
"load-grunt-tasks": "*", | ||
"grunt-livescript": "*", | ||
"grunt-contrib-uglify": "*", | ||
"grunt-contrib-watch": "*", | ||
"LiveScript": "1.3.x", | ||
"grunt": "0.4.x", | ||
"load-grunt-tasks": "0.4.x", | ||
"grunt-livescript": "0.5.x", | ||
"grunt-contrib-uglify": "0.4.x", | ||
"grunt-contrib-watch": "0.6.x", | ||
"karma": "*", | ||
@@ -28,3 +28,17 @@ "karma-qunit": "*", | ||
"promises-tests": "promises-aplus-tests tests/promises_tests_adapter" | ||
} | ||
}, | ||
"keywords": [ | ||
"ES6", | ||
"ECMAScript 6", | ||
"ES7", | ||
"ECMAScript 7", | ||
"Map", | ||
"Set", | ||
"WeakMap", | ||
"WeakSet", | ||
"Dict", | ||
"Promise", | ||
"Symbol", | ||
"console" | ||
] | ||
} |
360
README.md
@@ -18,194 +18,186 @@ # Core.js | ||
```livescript | ||
global -> object node | ||
signature from def in module | ||
------------------------------------------------------------------------------------------- | ||
global -> object node global | ||
Object | ||
.create(proto | null, descs?) -> object es5 | ||
.getPrototypeOf(object) -> proto | null es5 sham | ||
.setPrototypeOf(object, proto | null) -> &0 es6 sham | ||
.defineProperty(object, key, desc) -> &0 es5 sham | ||
.defineProperties(object, descs) -> &0 es5 sham | ||
.getOwnPropertyNames(object) -> array es5 sham | ||
.getOwnPropertyDescriptor(object, key) -> desc es5 | ||
.keys(object) -> array es5 | ||
.values(object) -> array es7 | ||
.entries(object) -> array es7 | ||
.assign(target, ...src) -> &0 es6 | ||
.is(a, b) -> bool es6 | ||
.isPrototype(proto, object) -> bool core | ||
.getOwnPropertyKeys(object) -> array core | ||
.getPropertyDescriptor(object, key) -> desc core | ||
.getOwnPropertyDescriptors(object) -> descs core | ||
.make(proto | null, props?) -> object core | ||
.define(object, props) -> &0 core | ||
.isObject(var) -> bool core | ||
.classof(var) -> string core | ||
.tie(object, key, ...args | _) -> fn(...args) core | ||
::[_](key, ...args | _) -> fn(...args) core | ||
.create(proto | null, descriptors?) -> object es5 es5 | ||
.getPrototypeOf(object) -> proto | null es5 sham es5 | ||
.setPrototypeOf(target, proto | null) -> target es6 sham es6 | ||
.defineProperty(target, key, desc) -> target es5 sham es5 | ||
.defineProperties(target, descriptors) -> target es5 sham es5 | ||
.getOwnPropertyNames(object) -> array es5 sham es5 | ||
.getOwnPropertyDescriptor(object, key) -> desc es5 es5 | ||
.keys(object) -> array es5 es5 | ||
.values(object) -> array es7 dict | ||
.entries(object) -> array es7 dict | ||
.assign(target, ...src) -> target es6 es6 | ||
.is(a, b) -> bool es6 es6 | ||
.isObject(var) -> bool core object | ||
.classof(var) -> string core object | ||
.define(target, mixin) -> target core object | ||
.make(proto | null, mixin?) -> object core object | ||
::toString() es6 fix es6 | ||
::[_](key) -> boundFn core binding | ||
Function | ||
::bind(object, ...args | _) -> fn(...args) es5 | ||
::part(...args | _) -> fn(...args) core | ||
::by(object | _, ...args | _) -> fn(...args) core | ||
::only(numberArguments, that /* = @ */) -> fn(...args) core | ||
::methodize() -> fn(that, ...args) core | ||
::invoke(args, that) -> var core | ||
::construct(args) -> object core | ||
::timeout(time, ...args) -> deferred core | ||
::interval(time, ...args) -> deferred core | ||
::immediate(...args) -> deferred core | ||
::bind(object, ...args | _) -> boundFn(...args) es5 es5 | ||
::part(...args | _) -> fn(...args) core binding | ||
::by(object | _, ...args | _) -> boundFn(...args) core binding | ||
::only(num, that /* = @ */) -> (fn | boundFn)(...args) core binding | ||
Array | ||
.isArray(var) -> bool es5 | ||
.from(iterable | array-like, fn(val, key, @)?, that) -> array es6 | ||
.of(...args) -> array es6 | ||
.{...Array::} js1.6 | ||
::slice(start?, end?) -> array es5 | ||
::join(string = ',') -> string es5 | ||
::indexOf(var, from?) -> int es5 | ||
::lastIndexOf(var, from?) -> int es5 | ||
::every(fn(val, key, @), that) -> bool es5 | ||
::some(fn(val, key, @), that) -> bool es5 | ||
::forEach(fn(val, key, @), that) -> void es5 | ||
::map(fn(val, key, @), that) -> array es5 | ||
::filter(fn(val, key, @), that) -> array es5 | ||
::reduce(fn(memo, val, key, @), memo?) -> var es5 | ||
::reduceRight(fn(memo, val, key, @), memo?) -> var es5 | ||
::fill(var, start?, end?) -> @ es5 | ||
::find(fn(val, key, @), that) -> var es6 | ||
::findIndex(fn(val, key, @), that) -> int es6 | ||
::values() -> iterator es6 | ||
::keys() -> iterator es6 | ||
::entries() -> iterator (entries) es6 | ||
::@@iterator() -> iterator es6 | ||
::get(index) -> var core | ||
::set(index, value) -> @ core | ||
::delete(index) -> bool core | ||
::contains(var, from?) -> bool es7 | ||
::clone() -> var core | ||
::turn(fn(memo, val, key, @), memo = []) -> memo core | ||
[new] Dict(itarable (entries) | object ?) -> dict core | ||
.isDict(var) -> bool core | ||
.has(object, key) -> bool core | ||
.get(object, key) -> val core | ||
.set(object, key, value) -> &0 core | ||
.forEach(object, fn(val, key, @), that) -> void core | ||
.map(object, fn(val, key, @), that) -> new @ core | ||
.filter(object, fn(val, key, @), that) -> new @ core | ||
.some(object, fn(val, key, @), that) -> bool core | ||
.every(object, fn(val, key, @), that) -> bool core | ||
.find(object, fn(val, key, @), that) -> val core | ||
.findKey(object, fn(val, key, @), that) -> key core | ||
.keyOf(object, var) -> key core | ||
.contains(object, var) -> bool core | ||
.reduce(object, fn(memo, val, key, @), memo?) -> var core | ||
.turn(object, fn(memo, val, key, @), memo = new @) -> memo core | ||
.clone(foo) -> var core | ||
new Set(iterable?) -> set es6 | ||
::add(key) -> @ es6 | ||
::clear() -> void es6 | ||
::delete(key) -> bool es6 | ||
::forEach(fn(el, el, @), that) -> void es6 | ||
::has(key) -> bool es6 | ||
::size -> uint es6 | ||
::values() -> iterator es6 | ||
::keys() -> iterator es6 | ||
::entries() -> iterator (entries) es6 | ||
::@@iterator() -> iterator es6 | ||
new Map(iterable (entries) ?) -> map es6 | ||
::clear() -> void es6 | ||
::delete(key) -> bool es6 | ||
::forEach(fn(val, key, @), that) -> void es6 | ||
::get(key) -> val es6 | ||
::has(key) -> bool es6 | ||
::set(key, val) -> @ es6 | ||
::size -> uint es6 | ||
::values() -> iterator es6 | ||
::keys() -> iterator es6 | ||
::entries() -> iterator (entries) es6 | ||
::@@iterator() -> iterator (entries) es6 | ||
new WeakSet(iterable?) -> weakset es6 | ||
::add(key) -> @ es6 | ||
::clear() -> void es6 | ||
::delete(key) -> bool es6 | ||
::has(key) -> bool es6 | ||
new WeakMap(iterable (entries) ?) -> weakmap es6 sham | ||
::clear() -> void es6 sham | ||
::delete(key) -> bool es6 | ||
::get(key) -> val es6 | ||
::has(key) -> bool es6 | ||
::set(key, val) -> @ es6 | ||
.isArray(var) -> bool es5 es5 | ||
.from(iterable | array-like, fn(val, index)?, that) -> array es6 es6 | ||
.of(...args) -> array es6 es6 | ||
.{...Array::} js1.6 array_statics | ||
::slice(start?, end?) -> array es5 fix es5 | ||
::join(string = ',') -> string es5 fix es5 | ||
::indexOf(var, from?) -> int es5 es5 | ||
::lastIndexOf(var, from?) -> int es5 es5 | ||
::every(fn(val, index, @), that) -> bool es5 es5 | ||
::some(fn(val, index, @), that) -> bool es5 es5 | ||
::forEach(fn(val, index, @), that) -> void es5 es5 | ||
::map(fn(val, index, @), that) -> array es5 es5 | ||
::filter(fn(val, index, @), that) -> array es5 es5 | ||
::reduce(fn(memo, val, index, @), memo?) -> var es5 es5 | ||
::reduceRight(fn(memo, val, index, @), memo?) -> var es5 es5 | ||
::fill(var, start?, end?) -> @ es5 es5 | ||
::find(fn(val, index, @), that) -> var es6 es6 | ||
::findIndex(fn(val, index, @), that) -> int es6 es6 | ||
::values() -> iterator es6 es6_iterators | ||
::keys() -> iterator es6 es6_iterators | ||
::entries() -> iterator (entries) es6 es6_iterators | ||
::@@iterator() -> iterator es6 es6_iterators | ||
::contains(var, from?) -> bool es7 array | ||
::turn(fn(memo, val, index, @), memo = []) -> memo core array | ||
[new] Dict(itarable (entries) | object ?) -> dict core dict | ||
.isDict(var) -> bool core dict | ||
.values(object) -> iterator core dict | ||
.keys(object) -> iterator core dict | ||
.entries(object) -> iterator (entries) core dict | ||
.has(object, key) -> bool core dict | ||
.get(object, key) -> val core dict | ||
.set(object, key, value) -> object core dict | ||
.forEach(object, fn(val, key, @), that) -> void core dict | ||
.map(object, fn(val, key, @), that) -> new @ core dict | ||
.filter(object, fn(val, key, @), that) -> new @ core dict | ||
.some(object, fn(val, key, @), that) -> bool core dict | ||
.every(object, fn(val, key, @), that) -> bool core dict | ||
.find(object, fn(val, key, @), that) -> val core dict | ||
.findKey(object, fn(val, key, @), that) -> key core dict | ||
.keyOf(object, var) -> key core dict | ||
.contains(object, var) -> bool core dict | ||
.reduce(object, fn(memo, val, key, @), memo?) -> var core dict | ||
.turn(object, fn(memo, val, key, @), memo = new @) -> memo core dict | ||
new Set(iterable?) -> set es6 es6_collections | ||
::add(key) -> @ es6 es6_collections | ||
::clear() -> void es6 es6_collections | ||
::delete(key) -> bool es6 es6_collections | ||
::forEach(fn(el, el, @), that) -> void es6 es6_collections | ||
::has(key) -> bool es6 es6_collections | ||
::size -> uint es6 es6_collections | ||
::values() -> iterator es6 es6_iterators | ||
::keys() -> iterator es6 es6_iterators | ||
::entries() -> iterator (entries) es6 es6_iterators | ||
::@@iterator() -> iterator es6 es6_iterators | ||
new Map(iterable (entries) ?) -> map es6 es6_collections | ||
::clear() -> void es6 es6_collections | ||
::delete(key) -> bool es6 es6_collections | ||
::forEach(fn(val, key, @), that) -> void es6 es6_collections | ||
::get(key) -> val es6 es6_collections | ||
::has(key) -> bool es6 es6_collections | ||
::set(key, val) -> @ es6 es6_collections | ||
::size -> uint es6 es6_collections | ||
::values() -> iterator es6 es6_iterators | ||
::keys() -> iterator es6 es6_iterators | ||
::entries() -> iterator (entries) es6 es6_iterators | ||
::@@iterator() -> iterator (entries) es6 es6_iterators | ||
new WeakSet(iterable?) -> weakset es6 es6_collections | ||
::add(key) -> @ es6 es6_collections | ||
::clear() -> void es6 es6_collections | ||
::delete(key) -> bool es6 es6_collections | ||
::has(key) -> bool es6 es6_collections | ||
new WeakMap(iterable (entries) ?) -> weakmap es6 sham es6_collections | ||
::clear() -> void es6 sham es6_collections | ||
::delete(key) -> bool es6 es6_collections | ||
::get(key) -> val es6 es6_collections | ||
::has(key) -> bool es6 es6_collections | ||
::set(key, val) -> @ es6 es6_collections | ||
String | ||
::trim() -> str es5 | ||
::contains(str, from?) -> bool es6 | ||
::startsWith(str, from?) -> bool es6 | ||
::endsWith(str, from?) -> bool es6 | ||
::repeat(num) -> str es6 | ||
::@@iterator() -> iterator es6 sham | ||
::escapeHTML() -> str core | ||
::unescapeHTML() -> str core | ||
::trim() -> str es5 es5 | ||
::contains(str, from?) -> bool es6 es6 | ||
::startsWith(str, from?) -> bool es6 es6 | ||
::endsWith(str, from?) -> bool es6 es6 | ||
::repeat(num) -> str es6 es6 | ||
::@@iterator() -> iterator es6 sham es6_iterators | ||
::escapeHTML() -> str core string | ||
::unescapeHTML() -> str core string | ||
RegExp | ||
.escape(str) -> str es7 | ||
.escape(str) -> str es7 regexp | ||
Number | ||
.EPSILON -> num es6 | ||
.isFinite(num) -> bool es6 | ||
.isInteger(num) -> bool es6 | ||
.isNaN(num) -> bool es6 | ||
.isSafeInteger(num) -> bool es6 | ||
.MAX_SAFE_INTEGER -> int es6 | ||
.MIN_SAFE_INTEGER -> int es6 | ||
.parseFloat(str) -> num es6 | ||
.parseInt(str) -> int es6 | ||
.toInteger(num) -> int core | ||
::times(fn(i, i, @), that) -> array core | ||
::random(lim = 0) -> num core | ||
::{...Math} core | ||
.EPSILON -> num es6 es6 | ||
.isFinite(num) -> bool es6 es6 | ||
.isInteger(num) -> bool es6 es6 | ||
.isNaN(num) -> bool es6 es6 | ||
.isSafeInteger(num) -> bool es6 es6 | ||
.MAX_SAFE_INTEGER -> int es6 es6 | ||
.MIN_SAFE_INTEGER -> int es6 es6 | ||
.parseFloat(str) -> num es6 es6 | ||
.parseInt(str) -> int es6 es6 | ||
::@@iterator() -> iterator core number | ||
::times(fn(i)?, that) -> array core number | ||
::random(lim = 0) -> num core number | ||
::{...Math} core number | ||
Math | ||
.acosh(num) -> num es6 | ||
.asinh(num) -> num es6 | ||
.atanh(num) -> num es6 | ||
.cbrt(num) -> num es6 | ||
.clz32(num) -> uint es6 | ||
.cosh(num) -> num es6 | ||
.expm1(num) -> num es6 | ||
.hypot(...args) -> num es6 | ||
.imul(num, num) -> int es6 | ||
.log1p(num) -> num es6 | ||
.log10(num) -> num es6 | ||
.log2(num) -> num es6 | ||
.sign(num) -> 1 | -1 | 0 | -0 | NaN es6 | ||
.sinh(num) -> num es6 | ||
.tanh(num) -> num es6 | ||
.trunc(num) -> num es6 | ||
.randomInt(lim1, lim2 = 0) -> int core | ||
.acosh(num) -> num es6 es6 | ||
.asinh(num) -> num es6 es6 | ||
.atanh(num) -> num es6 es6 | ||
.cbrt(num) -> num es6 es6 | ||
.clz32(num) -> uint es6 es6 | ||
.cosh(num) -> num es6 es6 | ||
.expm1(num) -> num es6 es6 | ||
.hypot(...args) -> num es6 es6 | ||
.imul(num, num) -> int es6 es6 | ||
.log1p(num) -> num es6 es6 | ||
.log10(num) -> num es6 es6 | ||
.log2(num) -> num es6 es6 | ||
.sign(num) -> 1 | -1 | 0 | -0 | NaN es6 es6 | ||
.sinh(num) -> num es6 es6 | ||
.tanh(num) -> num es6 es6 | ||
.trunc(num) -> num es6 es6 | ||
Date | ||
.now() -> int es5 | ||
.addLocale(key, object) -> @ core | ||
.locale(key?) -> key core | ||
::format(str, key?) -> str core | ||
::formatUTC(str, key?) -> str core | ||
Symbol(description?) -> symbol es6 sham | ||
.for(key) -> symbol es6 | ||
.keyFor(symbol) -> key es6 | ||
.iterator -> symbol es6 sham | ||
.toStringTag -> symbol es6 | ||
.pure() -> symbol || string core | ||
.set(object, key, val) -> &0 core | ||
new Promise(resolver(resolve(var), reject(var))) -> promise es6 | ||
::then(resolved(var), rejected(var)) -> promise es6 | ||
::catch(rejected(var)) -> promise es6 | ||
.resolve(var || promise) -> promise es6 | ||
.reject(var) -> promise es6 | ||
.all(iterable) -> promise es6 | ||
.race(iterable) -> promise es6 | ||
setTimeout(fn(...args), time, ...args) -> id w3c / whatwg | ||
setInterval(fn(...args), time, ...args) -> id w3c / whatwg | ||
setImmediate(fn(...args), ...args) -> id w3c / whatwg | ||
clearImmediate(id) -> void w3c / whatwg | ||
console(...args) -> void core | ||
.{...console API} console api | ||
.enable() -> void core | ||
.disable() -> void core | ||
$for(iterable, entries).of(fn(value, key?), that) -> void core | ||
.isIterable(var) -> bool core | ||
.getIterator(iterable) -> iterator core | ||
core core | ||
.{...global} core | ||
_ -> object core / undescore | ||
.now() -> int es5 es5 | ||
::format(str, key?) -> str core date | ||
::formatUTC(str, key?) -> str core date | ||
Symbol(description?) -> symbol es6 sham es6_symbol | ||
.for(key) -> symbol es6 es6_symbol | ||
.keyFor(symbol) -> key es6 es6_symbol | ||
.iterator -> symbol es6 sham es6_symbol | ||
.toStringTag -> symbol es6 es6_symbol | ||
.pure() -> symbol || string core es6_symbol | ||
.set(object, key, val) -> object core es6_symbol | ||
Reflect -> object es6 es6_symbol | ||
.ownKeys(object) -> array es6 es6_symbol | ||
new Promise(executor(resolve(var), reject(var))) -> promise es6 es6_promise | ||
::then(resolved(var), rejected(var)) -> promise es6 es6_promise | ||
::catch(rejected(var)) -> promise es6 es6_promise | ||
.resolve(var || promise) -> promise es6 es6_promise | ||
.reject(var) -> promise es6 es6_promise | ||
.all(iterable) -> promise es6 es6_promise | ||
.race(iterable) -> promise es6 es6_promise | ||
setTimeout(fn(...args), time, ...args) -> id w3c / whatwg timers | ||
setInterval(fn(...args), time, ...args) -> id w3c / whatwg timers | ||
setImmediate(fn(...args), ...args) -> id w3c / whatwg immediate | ||
clearImmediate(id) -> void w3c / whatwg immediate | ||
console(...args) -> void core console | ||
.{...console API} console api console | ||
.enable() -> void core console | ||
.disable() -> void core console | ||
$for(iterable, entries).of(fn(value, key?), that) -> void core es6_iterators | ||
.isIterable(var) -> bool core es6_iterators | ||
.getIterator(iterable) -> iterator core es6_iterators | ||
core core common | ||
.{...global} core common | ||
.addLocale(key, object) -> @ core date | ||
.locale(key?) -> key core date | ||
.noConflict() -> core core common | ||
_ -> object core / _ common | ||
``` |
@@ -1,21 +0,15 @@ | ||
/** | ||
* Array static methods | ||
* Strawman: http://wiki.ecmascript.org/doku.php?id=strawman:array_statics | ||
* JavaScript 1.6: https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/1.6#Array_and_String_generics | ||
*/ | ||
$define(STATIC, ARRAY, turn.call( | ||
// IE... getNames(ArrayProto), | ||
array( | ||
// ES3: | ||
'concat,join,pop,push,reverse,shift,slice,sort,splice,unshift,' + | ||
// ES5: | ||
'indexOf,lastIndexOf,every,some,forEach,map,filter,reduce,reduceRight,' + | ||
// ES6: | ||
'fill,find,findIndex,keys,values,entries,' + | ||
// Core: | ||
'get,set,delete,contains,clone,turn' | ||
), | ||
function(memo, key){ | ||
if(key in ArrayProto)memo[key] = ctx(call, ArrayProto[key]); | ||
}, {} | ||
)); | ||
// JavaScript 1.6 / Strawman array statics shim | ||
!function(){ | ||
function setArrayStatics(keys, length){ | ||
$define(STATIC, ARRAY, turn.call( | ||
array(keys), | ||
function(memo, key){ | ||
if(key in ArrayProto)memo[key] = ctx(call, ArrayProto[key], length); | ||
}, {} | ||
)); | ||
} | ||
setArrayStatics('pop,reverse,shift,keys,values,entries', 1); | ||
setArrayStatics('indexOf,every,some,forEach,map,filter,find,findIndex,contains', 3); | ||
setArrayStatics('join,slice,concat,push,splice,unshift,sort,' + | ||
'lastIndexOf,reduce,reduceRight,fill,turn'); | ||
}(); |
$define(PROTO, ARRAY, { | ||
/** | ||
* Alternatives: | ||
* http://sugarjs.com/api/Array/at | ||
* With Proxy: http://www.h3manth.com/new/blog/2013/negative-array-index-in-javascript/ | ||
*/ | ||
get: function(index){ | ||
var O = ES5Object(this) | ||
, length = toLength(this.length) | ||
, index = toInteger(index); | ||
if(index < 0)index += length; | ||
return O[index]; | ||
}, | ||
set: function(index, value){ | ||
var length = toLength(this.length) | ||
, index = toInteger(index); | ||
if(index < 0)index += length; | ||
this[index] = value; | ||
return this; | ||
}, | ||
'delete': function(index){ | ||
var length = toLength(this.length) | ||
, index = toInteger(index); | ||
if(index < 0)index += length; | ||
if(index >= length || index < 0)return false; | ||
splice.call(this, index, 1); | ||
return true; | ||
}, | ||
// ~ ES7 : https://github.com/domenic/Array.prototype.contains | ||
contains: function(searchElement, fromIndex){ | ||
var O = ES5Object(this) | ||
, length = toLength(O.length) | ||
, index = toInteger(fromIndex); | ||
if(index < 0)index = max(index + length, 0); | ||
while(length > index)if(sameValueZero(searchElement, O[index++]))return true; | ||
return false; | ||
}, | ||
clone: function(){ | ||
return clone(this, [], []); | ||
}, | ||
/** | ||
* Alternatives: | ||
* http://lodash.com/docs#transform | ||
*/ | ||
contains: createArrayContains(true) | ||
}); | ||
$define(PROTO + FORCED, ARRAY, { | ||
turn: turn | ||
}); |
@@ -1,10 +0,3 @@ | ||
!function(_){ | ||
$define(PROTO, FUNCTION, { | ||
/** | ||
* Partial apply. | ||
* Alternatives: | ||
* http://sugarjs.com/api/Function/fill | ||
* http://underscorejs.org/#partial | ||
* http://mootools.net/docs/core/Types/Function#Function:pass | ||
*/ | ||
!function(_, BOUND, toLocaleString){ | ||
$define(PROTO + FORCED, FUNCTION, { | ||
part: part, | ||
@@ -16,15 +9,15 @@ by: function(that){ | ||
, length = arguments.length | ||
, woctx = that === _ | ||
, i = woctx ? 0 : 1 | ||
, isThat = that === _ | ||
, i = +!isThat | ||
, indent = i | ||
, args; | ||
if(length < 2)return woctx ? ctx(call, fn, -1) : ctx(fn, that, -1); | ||
, it, args; | ||
if(isThat){ | ||
it = fn; | ||
fn = call; | ||
} else it = that; | ||
if(length < 2)return ctx(fn, it, -1); | ||
args = Array(length - indent); | ||
while(length > i)if((args[i - indent] = arguments[i++]) === _)holder = true; | ||
return partial(woctx ? call : fn, args, length, holder, _, true, woctx ? fn : that); | ||
return partial(fn, args, length, holder, _, true, it); | ||
}, | ||
/** | ||
* http://www.wirfs-brock.com/allen/posts/166 | ||
* http://habrahabr.ru/post/114737/ | ||
*/ | ||
only: function(numberArguments, that /* = @ */){ | ||
@@ -41,38 +34,12 @@ var fn = assertFunction(this) | ||
} | ||
}, | ||
/** | ||
* fn(a, b, c, ...) -> a.fn(b, c, ...) | ||
* Alternatives: | ||
* http://api.prototypejs.org/language/Function/prototype/methodize/ | ||
*/ | ||
methodize: function(){ | ||
var fn = this; | ||
return function(/* ...args */){ | ||
var args = [this] | ||
, i = 0; | ||
while(arguments.length > i)args.push(arguments[i++]); | ||
return invoke(fn, args); | ||
} | ||
} | ||
}); | ||
/** | ||
* Alternatives: | ||
* http://www.2ality.com/2013/06/auto-binding.html | ||
* http://livescript.net/#property-access -> foo~bar | ||
* http://lodash.com/docs#bindKey | ||
*/ | ||
function tie(key){ | ||
var that = this | ||
, _ = path._ | ||
, holder = false | ||
, length = arguments.length | ||
, i = 1, args; | ||
if(length < 2)return ctx(that[key], that, -1); | ||
args = Array(length - 1) | ||
while(length > i)if((args[i - 1] = arguments[i++]) === _)holder = true; | ||
return partial(that[key], args, length, holder, _, true, that); | ||
var that = this, bound; | ||
if(key === undefined || !(key in that))return toLocaleString.call(that); | ||
has(that, BOUND) || hidden(that, BOUND, {}); | ||
bound = that[BOUND]; | ||
return has(bound, key) ? bound[key] : (bound[key] = ctx(that[key], that, -1)); | ||
} | ||
$define(STATIC, OBJECT, {tie: core.tie = ctx(call, tie)}); | ||
@@ -82,6 +49,6 @@ hidden(path._, TO_STRING, function(){ | ||
}); | ||
DESCRIPTORS && hidden(ObjectProto, _, tie); | ||
hidden(FunctionProto, _, tie); | ||
hidden(ArrayProto, _, tie); | ||
hidden(RegExp[PROTOTYPE], _, tie); | ||
}(uid('tie')); | ||
hidden(ObjectProto, _, tie); | ||
DESC || hidden(ArrayProto, _, tie); | ||
// IE8- dirty hack - redefined toLocaleString is not enumerable | ||
}(DESC ? uid('tie') : TO_LOCALE, symbol('bound'), ObjectProto[TO_LOCALE]); |
@@ -0,1 +1,2 @@ | ||
// console cap | ||
!function(console){ | ||
@@ -8,5 +9,5 @@ var $console = turn.call( | ||
*/ | ||
array('assert,count,clear,debug,dir,dirxml,error,exception,' + | ||
'group,groupCollapsed,groupEnd,info,log,table,trace,warn,' + | ||
'markTimeline,profile,profileEnd,time,timeEnd,timeStamp'), | ||
array('assert,clear,count,debug,dir,dirxml,error,exception,group,groupCollapsed,' + | ||
'groupEnd,info,isIndependentlyComposed,log,markTimeline,profile,profileEnd,' + | ||
'table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn'), | ||
function(memo, key){ | ||
@@ -13,0 +14,0 @@ var fn = console[key]; |
@@ -11,19 +11,17 @@ !function(formatRegExp, flexioRegExp, locales, current, SECONDS, MINUTES, HOURS, MONTH, YEAR){ | ||
switch(part){ | ||
case 'ms' : var ms = get('Milliseconds'); // Milliseconds : 000-999 | ||
return ms > 99 ? ms : '0' + lz(ms); | ||
case 's' : return get(SECONDS); // Seconds : 0-59 | ||
case 'ss' : return lz(get(SECONDS)); // Seconds : 00-59 | ||
case 'm' : return get(MINUTES); // Minutes : 0-59 | ||
case 'mm' : return lz(get(MINUTES)); // Minutes : 00-59 | ||
case 'h' : return get(HOURS); // Hours : 0-23 | ||
case 'hh' : return lz(get(HOURS)); // Hours : 00-23 | ||
case 'D' : return get(DATE) // Date : 1-31 | ||
case 'DD' : return lz(get(DATE)); // Date : 01-31 | ||
case 'W' : return dict.W[get('Day')]; // Day : Понедельник | ||
case 'N' : return get(MONTH) + 1; // Month : 1-12 | ||
case 'NN' : return lz(get(MONTH) + 1); // Month : 01-12 | ||
case 'M' : return dict.M[get(MONTH)]; // Month : Январь | ||
case 'MM' : return dict.MM[get(MONTH)]; // Month : Января | ||
case 'YY' : return lz(get(YEAR) % 100); // Year : 14 | ||
case 'YYYY' : return get(YEAR); // Year : 2014 | ||
case 's' : return get(SECONDS); // Seconds : 0-59 | ||
case 'ss' : return lz(get(SECONDS)); // Seconds : 00-59 | ||
case 'm' : return get(MINUTES); // Minutes : 0-59 | ||
case 'mm' : return lz(get(MINUTES)); // Minutes : 00-59 | ||
case 'h' : return get(HOURS); // Hours : 0-23 | ||
case 'hh' : return lz(get(HOURS)); // Hours : 00-23 | ||
case 'D' : return get(DATE) // Date : 1-31 | ||
case 'DD' : return lz(get(DATE)); // Date : 01-31 | ||
case 'W' : return dict[0][get('Day')]; // Day : Понедельник | ||
case 'N' : return get(MONTH) + 1; // Month : 1-12 | ||
case 'NN' : return lz(get(MONTH) + 1); // Month : 01-12 | ||
case 'M' : return dict[2][get(MONTH)]; // Month : Январь | ||
case 'MM' : return dict[1][get(MONTH)]; // Month : Января | ||
case 'Y' : return get(YEAR); // Year : 2014 | ||
case 'YY' : return lz(get(YEAR) % 100); // Year : 14 | ||
} return part; | ||
@@ -42,16 +40,6 @@ }); | ||
} | ||
locales[lang] = { | ||
W : array(locale.weekdays), | ||
MM: split(1), | ||
M : split(2) | ||
}; | ||
return this; | ||
locales[lang] = [array(locale.weekdays), split(1), split(2)]; | ||
return core; | ||
} | ||
$define(STATIC, DATE, { | ||
locale: function(locale){ | ||
return has(locales, locale) ? current = locale : current; | ||
}, | ||
addLocale: addLocale | ||
}); | ||
$define(PROTO, DATE, { | ||
$define(PROTO + FORCED, DATE, { | ||
format: createFormat(false), | ||
@@ -62,8 +50,13 @@ formatUTC: createFormat(true) | ||
weekdays: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday', | ||
months: 'January,February,March,April,May,June,July,August,September,October,November,December' | ||
months: 'January,February,March,April,May,June,July,August,September,October,November,December' | ||
}); | ||
addLocale('ru', { | ||
weekdays: 'Воскресенье,Понедельник,Вторник,Среда,Четверг,Пятница,Суббота', | ||
months: 'Январ:я|ь,Феврал:я|ь,Март:а|,Апрел:я|ь,Ма:я|й,Июн:я|ь,Июл:я|ь,Август:а|,Сентябр:я|ь,Октябр:я|ь,Ноябр:я|ь,Декабр:я|ь' | ||
months: 'Январ:я|ь,Феврал:я|ь,Март:а|,Апрел:я|ь,Ма:я|й,Июн:я|ь,' + | ||
'Июл:я|ь,Август:а|,Сентябр:я|ь,Октябр:я|ь,Ноябр:я|ь,Декабр:я|ь' | ||
}); | ||
}(/\b\w{1,4}\b/g, /:(.*)\|(.*)$/, {}, 'en', 'Seconds', 'Minutes', 'Hours', 'Month', 'FullYear'); | ||
core.locale = function(locale){ | ||
return has(locales, locale) ? current = locale : current; | ||
}; | ||
core.addLocale = addLocale; | ||
}(/\b\w\w?\b/g, /:(.*)\|(.*)$/, {}, 'en', 'Seconds', 'Minutes', 'Hours', 'Month', 'FullYear'); |
@@ -5,3 +5,3 @@ !function(){ | ||
if(iterable != undefined){ | ||
if($for && isIterable(iterable))$for(iterable, true).of(function(key, value){ | ||
if(isIterable(iterable))forOf(iterable, true, function(key, value){ | ||
dict[key] = value; | ||
@@ -15,2 +15,24 @@ }); | ||
function DictIterator(iterated, kind){ | ||
set(this, ITER, {o: ES5Object(iterated), a: getKeys(iterated), i: 0, k: kind}); | ||
} | ||
createIterator(DictIterator, 'Dict', function(){ | ||
var iter = this[ITER] | ||
, index = iter.i++ | ||
, keys = iter.a | ||
, kind = iter.k | ||
, key, value; | ||
if(index >= keys.length)return createIterResultObject(1); | ||
key = keys[index]; | ||
if(kind == KEY) value = key; | ||
else if(kind == VALUE)value = iter.o[key]; | ||
else value = [key, iter.o[key]]; | ||
return createIterResultObject(0, value); | ||
}); | ||
function createDictIter(kind){ | ||
return function(it){ | ||
return new DictIterator(it, kind); | ||
} | ||
} | ||
/* | ||
@@ -30,4 +52,4 @@ * 0 -> forEach | ||
, isEvery = type == 4; | ||
return function(object, callbackfn, thisArg /* = undefined */){ | ||
var f = ctx(callbackfn, thisArg, 3) | ||
return function(object, callbackfn, that /* = undefined */){ | ||
var f = ctx(callbackfn, that, 3) | ||
, O = ES5Object(object) | ||
@@ -66,3 +88,3 @@ , keys = getKeys(O) | ||
else if(arguments.length < 3){ | ||
assert(length > i, REDUCE_ERROR); | ||
assert(length, REDUCE_ERROR); | ||
memo = O[keys[i++]]; | ||
@@ -79,3 +101,7 @@ } else memo = Object(init); | ||
} | ||
var findKey = createDictMethod(6); | ||
assign(Dict, { | ||
keys: createDictIter(KEY), | ||
values: createDictIter(VALUE), | ||
entries: createDictIter(KEY+VALUE), | ||
forEach: createDictMethod(0), | ||
@@ -87,19 +113,9 @@ map: createDictMethod(1), | ||
find: createDictMethod(5), | ||
findKey: createDictMethod(6), | ||
findKey: findKey, | ||
reduce: createDictReduce(false), | ||
turn: createDictReduce(true), | ||
keyOf: keyOf, | ||
contains: function(object, searchElement){ | ||
var O = ES5Object(object) | ||
, keys = getKeys(O) | ||
, length = keys.length | ||
, i = 0; | ||
while(length > i){ | ||
if(sameValueZero(O[keys[i++]], searchElement))return true; | ||
} | ||
return false; | ||
contains: function(object, el){ | ||
return (el == el ? keyOf(object, el) : findKey(object, sameNaN)) !== undefined; | ||
}, | ||
clone: function(it){ | ||
return clone(it, [], []); | ||
}, | ||
// Has / get / set own property | ||
@@ -112,6 +128,12 @@ has: has, | ||
isDict: function(it){ | ||
return getPrototypeOf(it) == Dict[PROTOTYPE]; | ||
return getPrototypeOf(it) === Dict[PROTOTYPE]; | ||
} | ||
}); | ||
$define(GLOBAL, {Dict: Dict}); | ||
$define(STATIC, OBJECT, { | ||
// ~ ES7 : http://esdiscuss.org/topic/april-8-2014-meeting-notes#content-1 | ||
values: createObjectToArray(false), | ||
// ~ ES7 : http://esdiscuss.org/topic/april-8-2014-meeting-notes#content-1 | ||
entries: createObjectToArray(true) | ||
}); | ||
$define(GLOBAL + FORCED, {Dict: Dict}); | ||
}(); |
194
src/es5.js
@@ -1,53 +0,13 @@ | ||
/** | ||
* ECMAScript 5 shim | ||
* http://es5.github.io/ | ||
*/ | ||
!function(){ | ||
var Empty = Function() | ||
, _classof = classof | ||
, whitespace = '[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]' | ||
// For fix IE 8- don't enum bug https://developer.mozilla.org/en-US/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug | ||
, slyKeys1 = array(TO_STRING + ',toLocaleString,valueOf,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,' + CONSTRUCTOR) | ||
, slyKeys2 = slyKeys1.concat(PROTOTYPE, 'length') | ||
, slyKeysLen1 = slyKeys1.length | ||
, dontEnumBug = !isEnumerable.call({toString: undefined}, TO_STRING) | ||
, $PROTO = symbol(PROTOTYPE) | ||
// Create object with null prototype | ||
, createDict = __PROTO__ | ||
? function(){ | ||
return {__proto__: null}; | ||
} | ||
: function(){ | ||
// Thrash, waste and sodomy | ||
var iframe = document[CREATE_ELEMENT]('iframe') | ||
, i = slyKeysLen1 | ||
, iframeDocument; | ||
iframe.style.display = 'none'; | ||
html.appendChild(iframe); | ||
iframe.src = 'javascript:'; | ||
iframeDocument = iframe.contentWindow.document; | ||
iframeDocument.open(); | ||
iframeDocument.write('<script>document.F=Object</script>'); | ||
iframeDocument.close(); | ||
createDict = iframeDocument.F; | ||
while(i--)delete createDict[PROTOTYPE][slyKeys1[i]]; | ||
return createDict(); | ||
} | ||
, createGetKeys = function(names, length, isNames){ | ||
return function(object){ | ||
var O = ES5Object(object) | ||
, i = 0 | ||
, result = [] | ||
, key; | ||
for(key in O)(key !== $PROTO) && has(O, key) && result.push(key); | ||
// Hidden names for Object.getOwnPropertyNames & don't enum bug fix for Object.keys | ||
if(dontEnumBug || isNames)while(length > i)if(has(O, key = names[i++])){ | ||
~indexOf.call(result, key) || result.push(key); | ||
} | ||
return result; | ||
} | ||
}; | ||
if(!DESCRIPTORS){ | ||
// ECMAScript 5 shim | ||
!function(IS_ENUMERABLE, Empty, _classof, $PROTO){ | ||
var whitespace = '[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004' + | ||
'\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]' | ||
// For fix IE 8- don't enum bug | ||
, keys1 = [CONSTRUCTOR, HAS_OWN, 'isPrototypeOf', IS_ENUMERABLE, TO_LOCALE, TO_STRING, 'valueOf'] | ||
, keys2 = keys1.concat('length', PROTOTYPE) | ||
, keysLen1 = keys1.length; | ||
if(!DESC){ | ||
getOwnDescriptor = function(O, P){ | ||
if(has(O, P))return descriptor(!isEnumerable.call(O, P), O[P]); | ||
if(has(O, P))return descriptor(!ObjectProto[IS_ENUMERABLE].call(O, P), O[P]); | ||
}; | ||
@@ -72,3 +32,3 @@ defineProperty = function(O, P, Attributes){ | ||
} | ||
$define(STATIC + FORCED * !DESCRIPTORS, OBJECT, { | ||
$define(STATIC + FORCED * !DESC, OBJECT, { | ||
// 19.1.2.6 / 15.2.3.3 Object.getOwnPropertyDescriptor(O, P) | ||
@@ -81,41 +41,75 @@ getOwnPropertyDescriptor: getOwnDescriptor, | ||
}); | ||
// Create object with `null` prototype | ||
function createDict(){ | ||
// Thrash, waste and sodomy: IE GC bug | ||
var iframe = document[CREATE_ELEMENT]('iframe') | ||
, i = keysLen1 | ||
, iframeDocument; | ||
iframe.style.display = 'none'; | ||
html.appendChild(iframe); | ||
iframe.src = 'javascript:'; | ||
// createDict = iframe.contentWindow.Object; | ||
// html.removeChild(iframe); | ||
iframeDocument = iframe.contentWindow.document; | ||
iframeDocument.open(); | ||
iframeDocument.write('<script>document.F=Object</script>'); | ||
iframeDocument.close(); | ||
createDict = iframeDocument.F; | ||
while(i--)delete createDict[PROTOTYPE][keys1[i]]; | ||
return createDict(); | ||
} | ||
function createGetKeys(names, length, isNames){ | ||
return function(object){ | ||
var O = ES5Object(object) | ||
, i = 0 | ||
, result = [] | ||
, key; | ||
for(key in O)if(key != $PROTO)has(O, key) && result.push(key); | ||
// Hidden names for Object.getOwnPropertyNames & don't enum bug fix for Object.keys | ||
while(length > i)if(has(O, key = names[i++])){ | ||
~indexOf.call(result, key) || result.push(key); | ||
} | ||
return result; | ||
} | ||
} | ||
$define(STATIC, OBJECT, { | ||
// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O) | ||
// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O) | ||
getPrototypeOf: getPrototypeOf = getPrototypeOf || function(O){ | ||
assertObject(O); | ||
if(has(O, $PROTO))return O[$PROTO]; | ||
if(__PROTO__ && '__proto__' in O)return O.__proto__; | ||
if(isFunction(O[CONSTRUCTOR]) && O != O[CONSTRUCTOR][PROTOTYPE])return O[CONSTRUCTOR][PROTOTYPE]; | ||
if(O instanceof Object)return ObjectProto; | ||
return null; | ||
if(has(assertObject(O), $PROTO))return O[$PROTO]; | ||
if(isFunction(O[CONSTRUCTOR]) && O instanceof O[CONSTRUCTOR]){ | ||
return O[CONSTRUCTOR][PROTOTYPE]; | ||
} return O instanceof Object ? ObjectProto : null; | ||
}, | ||
// 19.1.2.7 / 15.2.3.4 Object.getOwnPropertyNames(O) | ||
getOwnPropertyNames: getNames = getNames || createGetKeys(slyKeys2, slyKeys2.length, true), | ||
getOwnPropertyNames: getNames = getNames || createGetKeys(keys2, keys2.length, true), | ||
// 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties]) | ||
create: create = create || function(O, /*?*/Properties){ | ||
if(O === null)return Properties ? defineProperties(createDict(), Properties) : createDict(); | ||
Empty[PROTOTYPE] = assertObject(O); | ||
var result = new Empty(); | ||
Empty[PROTOTYPE] = null; | ||
if(Properties)defineProperties(result, Properties); | ||
// add __proto__ for Object.getPrototypeOf shim | ||
__PROTO__ || result[CONSTRUCTOR][PROTOTYPE] === O || (result[$PROTO] = O); | ||
return result; | ||
var result | ||
if(O !== null){ | ||
Empty[PROTOTYPE] = assertObject(O); | ||
result = new Empty(); | ||
Empty[PROTOTYPE] = null; | ||
// add "__proto__" for Object.getPrototypeOf shim | ||
result[CONSTRUCTOR][PROTOTYPE] === O || (result[$PROTO] = O); | ||
} else result = createDict(); | ||
return Properties === undefined ? result : defineProperties(result, Properties); | ||
}, | ||
// 19.1.2.14 / 15.2.3.14 Object.keys(O) | ||
keys: getKeys = getKeys || createGetKeys(slyKeys1, slyKeysLen1, false) | ||
keys: getKeys = getKeys || createGetKeys(keys1, keysLen1, false) | ||
}); | ||
// 19.2.3.2 / 15.3.4.5 Function.prototype.bind(thisArg [, arg1 [, arg2, …]]) | ||
// 19.2.3.2 / 15.3.4.5 Function.prototype.bind(thisArg, args...) | ||
$define(PROTO, FUNCTION, { | ||
bind: function(scope /*, args... */){ | ||
var fn = assertFunction(this) | ||
, args = slice.call(arguments, 1); | ||
bind: function(that /*, args... */){ | ||
var fn = assertFunction(this) | ||
, partArgs = slice.call(arguments, 1); | ||
function bound(/* args... */){ | ||
var _args = args.concat(slice.call(arguments)) | ||
, result, that; | ||
if(this instanceof fn)return isObject(result = invoke(that = create(fn[PROTOTYPE]), _args, scope)) ? result : that; | ||
return apply.call(fn, scope, _args); | ||
var args = partArgs.concat(slice.call(arguments)); | ||
if(this instanceof bound){ | ||
var instance = create(fn[PROTOTYPE]) | ||
, result = invoke(fn, args, instance); | ||
return isObject(result) ? result : instance; | ||
} return invoke(fn, args, that); | ||
} | ||
bound[PROTOTYPE] = undefined; | ||
return bound; | ||
@@ -149,3 +143,3 @@ } | ||
function createArrayReduce(isRight){ | ||
return function(callbackfn, memo /* = @.0 */){ | ||
return function(callbackfn, memo){ | ||
assertFunction(callbackfn); | ||
@@ -155,13 +149,13 @@ var O = ES5Object(this) | ||
, index = isRight ? length - 1 : 0 | ||
, inc = isRight ? -1 : 1; | ||
, i = isRight ? -1 : 1; | ||
if(2 > arguments.length)for(;;){ | ||
if(index in O){ | ||
memo = O[index]; | ||
index += inc; | ||
index += i; | ||
break; | ||
} | ||
index += inc; | ||
index += i; | ||
assert(isRight ? index >= 0 : length > index, REDUCE_ERROR); | ||
} | ||
for(;isRight ? index >= 0 : length > index; index += inc)if(index in O){ | ||
for(;isRight ? index >= 0 : length > index; index += i)if(index in O){ | ||
memo = callbackfn(memo, O[index], index, this); | ||
@@ -176,26 +170,17 @@ } | ||
// 22.1.3.15 / 15.4.4.19 Array.prototype.map(callbackfn [, thisArg]) | ||
map: createArrayMethod(1), | ||
map: createArrayMethod(1), | ||
// 22.1.3.7 / 15.4.4.20 Array.prototype.filter(callbackfn [, thisArg]) | ||
filter: createArrayMethod(2), | ||
filter: createArrayMethod(2), | ||
// 22.1.3.23 / 15.4.4.17 Array.prototype.some(callbackfn [, thisArg]) | ||
some: createArrayMethod(3), | ||
some: createArrayMethod(3), | ||
// 22.1.3.5 / 15.4.4.16 Array.prototype.every(callbackfn [, thisArg]) | ||
every: createArrayMethod(4), | ||
every: createArrayMethod(4), | ||
// 22.1.3.18 / 15.4.4.21 Array.prototype.reduce(callbackfn [, initialValue]) | ||
reduce: createArrayReduce(false), | ||
reduce: createArrayReduce(false), | ||
// 22.1.3.19 / 15.4.4.22 Array.prototype.reduceRight(callbackfn [, initialValue]) | ||
reduceRight: createArrayReduce(true), | ||
// 22.1.3.11 / 15.4.4.14 Array.prototype.indexOf(searchElement [, fromIndex]) | ||
indexOf: indexOf = indexOf || function(searchElement, fromIndex /* = 0 */){ | ||
var O = ES5Object(this) | ||
, length = toLength(O.length) | ||
, index = toInteger(fromIndex); | ||
if(index < 0)index = max(length + index, 0); | ||
for(;length > index; index++)if(index in O){ | ||
if(O[index] === searchElement)return index; | ||
} | ||
return -1; | ||
}, | ||
indexOf: indexOf = indexOf || createArrayContains(false), | ||
// 22.1.3.14 / 15.4.4.15 Array.prototype.lastIndexOf(searchElement [, fromIndex]) | ||
lastIndexOf: function(searchElement, fromIndex /* = @[*-1] */){ | ||
lastIndexOf: function(el, fromIndex /* = @[*-1] */){ | ||
var O = ES5Object(this) | ||
@@ -206,5 +191,3 @@ , length = toLength(O.length) | ||
if(index < 0)index = toLength(length + index); | ||
for(;index >= 0; index--)if(index in O){ | ||
if(O[index] === searchElement)return index; | ||
} | ||
for(;index >= 0; index--)if(index in O)if(O[index] === el)return index; | ||
return -1; | ||
@@ -216,3 +199,3 @@ } | ||
$define(PROTO, STRING, { | ||
trim: createEscaper(RegExp('^' + whitespace + '+|' + whitespace + '+$', 'g'), '') | ||
trim: createReplacer(RegExp('^' + whitespace + '+|' + whitespace + '+$', 'g'), '') | ||
}); | ||
@@ -225,5 +208,2 @@ | ||
if(isFunction(/./))isFunction = function(it){ | ||
return cof(it) == FUNCTION; | ||
} | ||
if(_classof(function(){return arguments}()) == OBJECT)classof = function(it){ | ||
@@ -233,2 +213,2 @@ var cof = _classof(it); | ||
} | ||
}(); | ||
}('propertyIsEnumerable', Function(), classof, symbol(PROTOTYPE)); |
@@ -1,14 +0,3 @@ | ||
/** | ||
* ECMAScript 6 collection polyfill | ||
* http://people.mozilla.org/~jorendorff/es6-draft.html | ||
* http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets | ||
* Alternatives: | ||
* https://github.com/Benvie/harmony-collections | ||
* https://github.com/eriwen/es6-map-shim | ||
* https://github.com/EliSnow/Blitz-Collections | ||
* https://github.com/montagejs/collections | ||
* https://github.com/Polymer/WeakMap/blob/master/weakmap.js | ||
*/ | ||
// ECMAScript 6 collections shim | ||
!function(){ | ||
SHIM = symbol('shim'); | ||
var KEYS = COLLECTION_KEYS = symbol('keys') | ||
@@ -19,3 +8,3 @@ , VALUES = symbol('values') | ||
, WEAKID = symbol('weakId') | ||
, SIZE = DESCRIPTORS ? symbol('size') : 'size' | ||
, SIZE = DESC ? symbol('size') : 'size' | ||
, uid = 0 | ||
@@ -28,5 +17,3 @@ , wid = 0; | ||
function initFromIterable(that, iterable){ | ||
if(iterable != undefined && $for){ | ||
$for(iterable, isMap).of(that[ADDER_KEY], that); | ||
} | ||
if(iterable != undefined)forOf(iterable, isMap, that[ADDER_KEY], that); | ||
return that; | ||
@@ -52,3 +39,3 @@ } | ||
// wrap to init collections from iterable | ||
if(!(ITERATOR in ArrayProto && collection.has(test_key))){ | ||
if(!(SYMBOL_ITERATOR in ArrayProto && collection.has(test_key))){ | ||
C = function(iterable){ | ||
@@ -80,3 +67,3 @@ assertInstance(this, C, NAME); | ||
if(!has(it, STOREID)){ | ||
if(create)set(it, STOREID, ++uid); | ||
if(create)hidden(it, STOREID, ++uid); | ||
else return ''; | ||
@@ -93,5 +80,5 @@ } | ||
clear: function(){ | ||
set(this, KEYS, create(null)); | ||
if($VALUES == VALUES)set(this, VALUES, create(null)); | ||
set(this, SIZE, 0); | ||
hidden(this, SIZE, 0); | ||
hidden(this, KEYS, create(null)); | ||
if($VALUES == VALUES)hidden(this, VALUES, create(null)); | ||
}, | ||
@@ -113,4 +100,4 @@ // 23.1.3.3 Map.prototype.delete(key) | ||
// 23.1.3.5 Map.prototype.forEach(callbackfn, thisArg = undefined) | ||
forEach: function(callbackfn, thisArg /* = undefined */){ | ||
var f = ctx(callbackfn, thisArg, 3) | ||
forEach: function(callbackfn, that /* = undefined */){ | ||
var f = ctx(callbackfn, that, 3) | ||
, values = this[$VALUES] | ||
@@ -169,3 +156,3 @@ , keys = this[KEYS] | ||
function getWeakData(it){ | ||
has(it, WEAKDATA) || set(it, WEAKDATA, {}); | ||
has(it, WEAKDATA) || hidden(it, WEAKDATA, {}); | ||
return it[WEAKDATA]; | ||
@@ -180,3 +167,3 @@ } | ||
clear: function(){ | ||
set(this, WEAKID, wid++); | ||
hidden(this, WEAKID, wid++); | ||
}, | ||
@@ -183,0 +170,0 @@ // 23.3.3.3 WeakMap.prototype.delete(key) |
@@ -1,32 +0,12 @@ | ||
!function($$ITERATOR){ | ||
var FFITERATOR = $$ITERATOR in ArrayProto | ||
, KEY = 1 | ||
, VALUE = 2 | ||
, ITERATED = symbol('iterated') | ||
, KIND = symbol('kind') | ||
, INDEX = symbol('index') | ||
, KEYS = symbol('keys') | ||
, ENTRIES = symbol('entries') | ||
, getValues = createObjectToArray(false) | ||
, Iterators = {}; | ||
// ECMAScript 6 iterators shim | ||
!function(){ | ||
var getValues = createObjectToArray(false); | ||
function createIterResultObject(done, value){ | ||
return {value: value, done: !!done}; | ||
} | ||
function createIteratorClass(Constructor, NAME, Base, next, DEFAULT){ | ||
Constructor[PROTOTYPE] = {}; | ||
// 22.1.5.2.1 %ArrayIteratorPrototype%.next() | ||
// 23.1.5.2.1 %MapIteratorPrototype%.next() | ||
// 23.2.5.2.1 %SetIteratorPrototype%.next() | ||
hidden(Constructor[PROTOTYPE], 'next', next); | ||
// 22.1.5.2.2 %ArrayIteratorPrototype%[@@iterator]() | ||
// 23.1.5.2.2 %MapIteratorPrototype%[@@iterator]() | ||
// 23.2.5.2.2 %SetIteratorPrototype%[@@iterator]() | ||
hidden(Constructor[PROTOTYPE], ITERATOR, returnThis); | ||
// Add iterator for FF iterator protocol | ||
FFITERATOR && hidden(Constructor[PROTOTYPE], $$ITERATOR, returnThis); | ||
// 22.1.5.2.3 %ArrayIteratorPrototype%[@@toStringTag] | ||
// 23.1.5.2.3 %MapIteratorPrototype%[@@toStringTag] | ||
// 23.2.5.2.3 %SetIteratorPrototype%[@@toStringTag] | ||
setToStringTag(Constructor, NAME + ' Iterator'); | ||
function defineStdIterators(Base, NAME, DEFAULT, Constructor, next){ | ||
function createIter(kind){ | ||
return function(){ | ||
return new Constructor(this, kind); | ||
} | ||
} | ||
createIterator(Constructor, NAME, next); | ||
$define(PROTO, NAME, { | ||
@@ -36,11 +16,11 @@ // 22.1.3.4 Array.prototype.entries() | ||
// 23.2.3.5 Set.prototype.entries() | ||
entries: createIteratorFactory(Constructor, KEY+VALUE), | ||
entries: createIter(KEY+VALUE), | ||
// 22.1.3.13 Array.prototype.keys() | ||
// 23.1.3.8 Map.prototype.keys() | ||
// 23.2.3.8 Set.prototype.keys() | ||
keys: createIteratorFactory(Constructor, KEY), | ||
keys: createIter(KEY), | ||
// 22.1.3.29 Array.prototype.values() | ||
// 23.1.3.11 Map.prototype.values() | ||
// 23.2.3.10 Set.prototype.values() | ||
values: createIteratorFactory(Constructor, VALUE) | ||
values: createIter(VALUE) | ||
}); | ||
@@ -50,42 +30,14 @@ // 22.1.3.30 Array.prototype[@@iterator]() | ||
// 23.2.3.11 Set.prototype[@@iterator]() | ||
Base && defineIterator(Base, NAME, createIteratorFactory(Constructor, DEFAULT)); | ||
Base && defineIterator(Base, NAME, createIter(DEFAULT)); | ||
} | ||
function createIteratorFactory(Constructor, kind){ | ||
return function(){ | ||
return new Constructor(this, kind); | ||
} | ||
} | ||
function defineIterator(Constructor, NAME, value){ | ||
var proto = Constructor[PROTOTYPE] | ||
, has$$ITERATOR = has(proto, $$ITERATOR); | ||
var iter = has(proto, ITERATOR) | ||
? proto[ITERATOR] | ||
: has$$ITERATOR | ||
? proto[$$ITERATOR] | ||
: value; | ||
if(framework){ | ||
// Define iterator | ||
!has(proto, ITERATOR) && hidden(proto, ITERATOR, iter); | ||
// FF fix | ||
if(has$$ITERATOR)hidden(getPrototypeOf(iter.call(new Constructor)), ITERATOR, returnThis); | ||
// Add iterator for FF iterator protocol | ||
else FFITERATOR && hidden(proto, $$ITERATOR, iter); | ||
} | ||
// Plug for library | ||
Iterators[NAME] = iter; | ||
// FF & v8 fix | ||
Iterators[NAME + ' Iterator'] = returnThis; | ||
} | ||
// 22.1.5.1 CreateArrayIterator Abstract Operation | ||
function ArrayIterator(iterated, kind){ | ||
set(this, ITERATED, ES5Object(iterated)); | ||
set(this, KIND, kind); | ||
set(this, INDEX, 0); | ||
} | ||
defineStdIterators(Array, ARRAY, VALUE, function(iterated, kind){ | ||
set(this, ITER, {o: ES5Object(iterated), i: 0, k: kind}); | ||
// 22.1.5.2.1 %ArrayIteratorPrototype%.next() | ||
createIteratorClass(ArrayIterator, ARRAY, Array, function(){ | ||
var iterated = this[ITERATED] | ||
, index = this[INDEX]++ | ||
, kind = this[KIND] | ||
}, function(){ | ||
var iter = this[ITER] | ||
, iterated = iter.o | ||
, index = iter.i++ | ||
, kind = iter.k | ||
, value; | ||
@@ -97,3 +49,3 @@ if(index >= iterated.length)return createIterResultObject(1); | ||
return createIterResultObject(0, value); | ||
}, VALUE); | ||
}); | ||
@@ -106,4 +58,4 @@ // 21.1.3.27 String.prototype[@@iterator]() - SHAM, TODO | ||
// 23.1.5.1 CreateMapIterator Abstract Operation | ||
function MapIterator(iterated, kind){ | ||
var that = this, keys; | ||
defineStdIterators(Map, MAP, KEY+VALUE, function(iterated, kind){ | ||
var keys; | ||
if(Map[SHIM])keys = getValues(iterated[COLLECTION_KEYS]); | ||
@@ -113,14 +65,10 @@ else Map[PROTOTYPE][FOR_EACH].call(iterated, function(val, key){ | ||
}, keys = []); | ||
set(that, ITERATED, iterated); | ||
set(that, KIND, kind); | ||
set(that, INDEX, 0); | ||
set(that, KEYS, keys); | ||
} | ||
set(this, ITER, {o: iterated, k: kind, a: keys, i: 0}); | ||
// 23.1.5.2.1 %MapIteratorPrototype%.next() | ||
createIteratorClass(MapIterator, MAP, Map, function(){ | ||
var that = this | ||
, iterated = that[ITERATED] | ||
, keys = that[KEYS] | ||
, index = that[INDEX]++ | ||
, kind = that[KIND] | ||
}, function(){ | ||
var iter = this[ITER] | ||
, iterated = iter.o | ||
, keys = iter.a | ||
, index = iter.i++ | ||
, kind = iter.k | ||
, key, value; | ||
@@ -133,6 +81,6 @@ if(index >= keys.length)return createIterResultObject(1); | ||
return createIterResultObject(0, value); | ||
}, KEY+VALUE); | ||
}); | ||
// 23.2.5.1 CreateSetIterator Abstract Operation | ||
function SetIterator(iterated, kind){ | ||
defineStdIterators(Set, SET, VALUE, function(iterated, kind){ | ||
var keys; | ||
@@ -143,37 +91,25 @@ if(Set[SHIM])keys = getValues(iterated[COLLECTION_KEYS]); | ||
}, keys = []); | ||
set(this, KIND, kind); | ||
set(this, KEYS, keys.reverse()); | ||
} | ||
set(this, ITER, {k: kind, a: keys.reverse(), l: keys.length}); | ||
// 23.2.5.2.1 %SetIteratorPrototype%.next() | ||
createIteratorClass(SetIterator, SET, Set, function(){ | ||
var keys = this[KEYS] | ||
}, function(){ | ||
var iter = this[ITER] | ||
, keys = iter.a | ||
, key; | ||
if(!keys.length)return createIterResultObject(1); | ||
key = keys.pop(); | ||
return createIterResultObject(0, this[KIND] == KEY+VALUE ? [key, key] : key); | ||
}, VALUE); | ||
return createIterResultObject(0, iter.k == KEY+VALUE ? [key, key] : key); | ||
}); | ||
$for = function(iterable, entries){ | ||
function $for(iterable, entries){ | ||
if(!(this instanceof $for))return new $for(iterable, entries); | ||
set(this, ITERATED, iterable); | ||
set(this, ENTRIES, entries); | ||
set(this, ITER, {o: iterable, e: entries}); | ||
} | ||
$for[PROTOTYPE].of = function(fn, that){ | ||
var iterator = getIterator(this[ITERATED]) | ||
, entries = this[ENTRIES] | ||
, f = ctx(fn, that, entries ? 2 : 1) | ||
, step; | ||
while(!(step = iterator.next()).done){ | ||
if((entries ? invoke(f, step.value) : f(step.value)) === false)return; | ||
} | ||
var data = this[ITER]; | ||
forOf(data.o, data.e, fn, that); | ||
} | ||
$for.isIterable = isIterable; | ||
$for.getIterator = getIterator; | ||
$for.isIterable = isIterable = function(it){ | ||
return (it != undefined && ITERATOR in it) || has(Iterators, classof(it)); | ||
} | ||
$for.getIterator = getIterator = function(it){ | ||
return assertObject((it[ITERATOR] || Iterators[classof(it)]).call(it)); | ||
} | ||
$define(GLOBAL, {$for: $for}); | ||
}('@@iterator'); | ||
$define(GLOBAL + FORCED, {$for: $for}); | ||
}(); |
@@ -1,13 +0,7 @@ | ||
/** | ||
* ES6 Promises | ||
* http://people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects | ||
* https://github.com/domenic/promises-unwrapping | ||
* Based on https://github.com/getify/native-promise-only/ | ||
*/ | ||
!function(Promise){ | ||
// ES6 promises shim | ||
// Based on https://github.com/getify/native-promise-only/ | ||
!function(Promise, test){ | ||
isFunction(Promise) && isFunction(Promise.resolve) | ||
&& function(promise){ | ||
return Promise.resolve(promise) == promise; | ||
}(new Promise(Function())) | ||
|| !function(asap, DEF){ | ||
&& Promise.resolve(test = new Promise(Function())) == test | ||
|| function(asap, DEF){ | ||
function isThenable(o){ | ||
@@ -51,3 +45,3 @@ var then; | ||
if(then = isThenable(msg)){ | ||
wrapper = {def: def, done : false}; // wrap | ||
wrapper = {def: def, done: false}; // wrap | ||
then.call(msg, ctx(resolve, wrapper, 1), ctx(reject, wrapper, 1)); | ||
@@ -60,3 +54,3 @@ } else { | ||
} catch(err){ | ||
reject.call(wrapper || {def: def, done : false}, err); // wrap | ||
reject.call(wrapper || {def: def, done: false}, err); // wrap | ||
} | ||
@@ -77,4 +71,4 @@ } | ||
assertInstance(this, Promise, PROMISE); | ||
var def = {chain: [], state: 0, done : false, msg: undefined}; | ||
set(this, DEF, def); | ||
var def = {chain: [], state: 0, done: false, msg: undefined}; | ||
hidden(this, DEF, def); | ||
try { | ||
@@ -108,3 +102,3 @@ executor(ctx(resolve, def, 1), ctx(reject, def, 1)); | ||
return new Promise(function(resolve, reject){ | ||
$for(iterable).of(push, values); | ||
forOf(iterable, false, push, values); | ||
var remaining = values.length | ||
@@ -125,3 +119,3 @@ , results = Array(remaining); | ||
return new Promise(function(resolve, reject){ | ||
$for(iterable).of(function(promise){ | ||
forOf(iterable, false, function(promise){ | ||
Promise.resolve(promise).then(resolve, reject); | ||
@@ -139,5 +133,6 @@ }); | ||
hidden(Promise, 'resolve', function(x){ | ||
return isObject(x) && getPrototypeOf(x) === this[PROTOTYPE] ? x : new this(function(resolve, reject){ | ||
resolve(x); | ||
}); | ||
return isObject(x) && getPrototypeOf(x) === this[PROTOTYPE] | ||
? x : new this(function(resolve, reject){ | ||
resolve(x); | ||
}); | ||
}); | ||
@@ -144,0 +139,0 @@ }(nextTick || setImmediate, symbol('def')); |
@@ -1,7 +0,3 @@ | ||
/** | ||
* ECMAScript 6 Symbol | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol | ||
* http://people.mozilla.org/~jorendorff/es6-draft.html#sec-symbol-objects | ||
*/ | ||
!function(TAG, $ITERATOR, $TOSTRINGTAG, SymbolRegistry){ | ||
// ECMAScript 6 symbols shim | ||
!function(TAG, $TO_STRING_TAG, SymbolRegistry){ | ||
// 19.4.1.1 Symbol([description]) | ||
@@ -18,3 +14,3 @@ if(!isNative(Symbol)){ | ||
}); | ||
return hidden(create(Symbol[PROTOTYPE]), TAG, tag); | ||
return set(create(Symbol[PROTOTYPE]), TAG, tag); | ||
} | ||
@@ -25,8 +21,5 @@ hidden(Symbol[PROTOTYPE], TO_STRING, function(){ | ||
} | ||
ITERATOR = $ITERATOR in Symbol | ||
? Symbol[$ITERATOR] | ||
: uid(SYMBOL + '.' + $ITERATOR); | ||
TOSTRINGTAG = $TOSTRINGTAG in Symbol | ||
? Symbol[$TOSTRINGTAG] | ||
: Symbol(SYMBOL + '.' + $TOSTRINGTAG); | ||
TO_STRING_TAG = $TO_STRING_TAG in Symbol | ||
? Symbol[$TO_STRING_TAG] | ||
: Symbol(SYMBOL + '.' + $TO_STRING_TAG); | ||
$define(GLOBAL + WRAP, {Symbol: Symbol}); | ||
@@ -36,10 +29,12 @@ $define(STATIC, SYMBOL, { | ||
'for': function(key){ | ||
return has(SymbolRegistry, key += '') ? SymbolRegistry[key] : SymbolRegistry[key] = Symbol(key); | ||
return has(SymbolRegistry, key += '') | ||
? SymbolRegistry[key] | ||
: SymbolRegistry[key] = Symbol(key); | ||
}, | ||
// 19.4.2.6 Symbol.iterator | ||
iterator: ITERATOR, | ||
iterator: SYMBOL_ITERATOR, | ||
// 19.4.2.7 Symbol.keyFor(sym) | ||
keyFor: part.call(keyOf, SymbolRegistry), | ||
// 19.4.2.10 Symbol.toStringTag | ||
toStringTag: TOSTRINGTAG, | ||
toStringTag: TO_STRING_TAG, | ||
pure: symbol, | ||
@@ -49,2 +44,4 @@ set: set | ||
setToStringTag(Symbol, SYMBOL); | ||
}(symbol('tag'), 'iterator', TO_STRING + 'Tag', {}); | ||
// 26.1.11 Reflect.ownKeys (target) | ||
$define(GLOBAL, {Reflect: {ownKeys: ownKeys}}); | ||
}(symbol('tag'), TO_STRING + 'Tag', {}); |
129
src/es6.js
@@ -1,24 +0,18 @@ | ||
/** | ||
* ECMAScript 6 shim | ||
* http://people.mozilla.org/~jorendorff/es6-draft.html | ||
*/ | ||
!function(isFinite){ | ||
// 20.2.2.28 Math.sign(x) | ||
function sign(it){ | ||
return (it = +it) == 0 || it != it ? it : it < 0 ? -1 : 1; | ||
} | ||
// ECMAScript 6 shim | ||
!function(isFinite, tmp){ | ||
$define(STATIC, OBJECT, { | ||
// 19.1.3.1 Object.assign(target, source) | ||
// The assign function is used to copy the values of all of the enumerable | ||
// own properties from a source object to a target object. | ||
assign: assign, | ||
// 19.1.3.10 Object.is(value1, value2) | ||
is: same | ||
is: function(x, y){ | ||
return x === y ? x !== 0 || 1 / x === 1 / y : x != x && y != y; | ||
} | ||
}); | ||
// 19.1.3.19 Object.setPrototypeOf(O, proto) | ||
// Works with __proto__ only. Old v8 can't works with null proto objects. | ||
__PROTO__ && function(set){ | ||
var buggy; | ||
try { set({}, ArrayProto) } | ||
catch(e){ buggy = true } | ||
'__proto__' in ObjectProto && function(buggy, set){ | ||
try { | ||
set = ctx(call, getOwnDescriptor(ObjectProto, '__proto__').set, 2); | ||
set({}, ArrayProto); | ||
} catch(e){ buggy = true } | ||
$define(STATIC, OBJECT, { | ||
@@ -33,3 +27,20 @@ setPrototypeOf: function(O, proto){ | ||
}); | ||
}(ctx(call, getOwnDescriptor(ObjectProto, '__proto__').set, 2)); | ||
}(); | ||
// 20.1.2.3 Number.isInteger(number) | ||
var isInteger = Number.isInteger || function(it){ | ||
return isFinite(it) && floor(it) === it; | ||
} | ||
// 20.2.2.28 Math.sign(x) | ||
, sign = Math.sign || function sign(it){ | ||
return (it = +it) == 0 || it != it ? it : it < 0 ? -1 : 1; | ||
} | ||
, abs = Math.abs | ||
, exp = Math.exp | ||
, log = Math.log | ||
, sqrt = Math.sqrt; | ||
// 20.2.2.5 Math.asinh(x) | ||
function asinh(x){ | ||
return !isFinite(x = +x) || x == 0 ? x : x < 0 ? -asinh(-x) : log(x + sqrt(x * x + 1)); | ||
} | ||
$define(STATIC, NUMBER, { | ||
@@ -43,9 +54,5 @@ // 20.1.2.1 Number.EPSILON | ||
// 20.1.2.3 Number.isInteger(number) | ||
isInteger: function(it){ | ||
return isFinite(it) && floor(it) === it; | ||
}, | ||
isInteger: isInteger, | ||
// 20.1.2.4 Number.isNaN(number) | ||
isNaN: function(number){ | ||
return number != number; | ||
}, | ||
isNaN: sameNaN, | ||
// 20.1.2.5 Number.isSafeInteger(number) | ||
@@ -64,14 +71,4 @@ isSafeInteger: function(number){ | ||
}); | ||
var isInteger = Number.isInteger | ||
, abs = Math.abs | ||
, exp = Math.exp | ||
, log = Math.log | ||
, sqrt = Math.sqrt | ||
, Oxffff = 0xffff; | ||
function asinh(x){ | ||
return !isFinite(x = +x) || x === 0 ? x : x < 0 ? -asinh(-x) : log(x + sqrt(x * x + 1)); | ||
} | ||
$define(STATIC, MATH, { | ||
// 20.2.2.3 Math.acosh(x) | ||
// Returns an implementation-dependent approximation to the inverse hyperbolic cosine of x. | ||
acosh: function(x){ | ||
@@ -81,11 +78,8 @@ return log(x + sqrt(x * x - 1)); | ||
// 20.2.2.5 Math.asinh(x) | ||
// Returns an implementation-dependent approximation to the inverse hyperbolic sine of x. | ||
asinh: asinh, | ||
// 20.2.2.7 Math.atanh(x) | ||
// Returns an implementation-dependent approximation to the inverse hyperbolic tangent of x. | ||
atanh: function(x){ | ||
return x === 0 ? x : .5 * log((1 + x) / (1 - x)); | ||
return x == 0 ? +x : log((1 + +x) / (1 - x)) / 2; | ||
}, | ||
// 20.2.2.9 Math.cbrt(x) | ||
// Returns an implementation-dependent approximation to the cube root of x. | ||
cbrt: function(x){ | ||
@@ -99,3 +93,2 @@ return sign(x) * pow(abs(x), 1 / 3); | ||
// 20.2.2.12 Math.cosh(x) | ||
// Returns an implementation-dependent approximation to the hyperbolic cosine of x. | ||
cosh: function(x){ | ||
@@ -105,5 +98,4 @@ return (exp(x) + exp(-x)) / 2; | ||
// 20.2.2.14 Math.expm1(x) | ||
// Returns an implementation-dependent approximation to subtracting 1 from the exponential function of x | ||
expm1: function(x){ | ||
return same(x, -0) ? -0 : x > -1e-6 && x < 1e-6 ? x + x * x / 2 : exp(x) - 1; | ||
return x == 0 ? +x : x > -1e-6 && x < 1e-6 ? +x + x * x / 2 : exp(x) - 1; | ||
}, | ||
@@ -113,4 +105,2 @@ // 20.2.2.16 Math.fround(x) | ||
// 20.2.2.17 Math.hypot([value1[, value2[, … ]]]) | ||
// Returns an implementation-dependent approximation of the square root | ||
// of the sum of squares of its arguments. | ||
hypot: function(value1, value2){ | ||
@@ -129,16 +119,14 @@ var sum = 0 | ||
imul: function(x, y){ | ||
var xh = Oxffff & x >>> 0x10 | ||
, xl = Oxffff & x | ||
, yh = Oxffff & y >>> 0x10 | ||
, yl = Oxffff & y; | ||
return 0 | xl * yl + (xh * yl + xl * yh << 0x10 >>> 0); | ||
var UInt16 = 0xffff | ||
, xh = UInt16 & x >>> 16 | ||
, xl = UInt16 & x | ||
, yh = UInt16 & y >>> 16 | ||
, yl = UInt16 & y; | ||
return 0 | xl * yl + (xh * yl + xl * yh << 16 >>> 0); | ||
}, | ||
// 20.2.2.20 Math.log1p(x) | ||
// Returns an implementation-dependent approximation to the natural logarithm of 1 + x. | ||
// The result is computed in a way that is accurate even when the value of x is close to zero. | ||
log1p: function(x){ | ||
return (x > -1e-8 && x < 1e-8) ? (x - x * x / 2) : log(1 + x); | ||
return x > -1e-8 && x < 1e-8 ? x - x * x / 2 : log(1 + +x); | ||
}, | ||
// 20.2.2.21 Math.log10(x) | ||
// Returns an implementation-dependent approximation to the base 10 logarithm of x. | ||
log10: function(x){ | ||
@@ -148,3 +136,2 @@ return log(x) / Math.LN10; | ||
// 20.2.2.22 Math.log2(x) | ||
// Returns an implementation-dependent approximation to the base 2 logarithm of x. | ||
log2: function(x){ | ||
@@ -154,22 +141,15 @@ return log(x) / Math.LN2; | ||
// 20.2.2.28 Math.sign(x) | ||
// Returns the sign of the x, indicating whether x is positive, negative or zero. | ||
sign: sign, | ||
// 20.2.2.30 Math.sinh(x) | ||
// Returns an implementation-dependent approximation to the hyperbolic sine of x. | ||
sinh: function(x){ | ||
return (x = +x) == -Infinity || x == 0 ? x : (exp(x) - exp(-x)) / 2; | ||
return x == 0 ? +x : (exp(x) - exp(-x)) / 2; | ||
}, | ||
// 20.2.2.33 Math.tanh(x) | ||
// Returns an implementation-dependent approximation to the hyperbolic tangent of x. | ||
tanh: function(x){ | ||
return isFinite(x = +x) ? x == 0 ? x : (exp(x) - exp(-x)) / (exp(x) + exp(-x)) : sign(x); | ||
return isFinite(x) ? x == 0 ? +x : (exp(x) - exp(-x)) / (exp(x) + exp(-x)) : sign(x); | ||
}, | ||
// 20.2.2.34 Math.trunc(x) | ||
// Returns the integral part of the number x, removing any fractional digits. | ||
// If x is already an integer, the result is x. | ||
trunc: function(x){ | ||
return (x = +x) == 0 ? x : (x > 0 ? floor : ceil)(x); | ||
} | ||
trunc: trunc | ||
}); | ||
// 20.2.1.9 Math [ @@toStringTag ] | ||
// 20.2.1.9 Math[@@toStringTag] | ||
setToStringTag(Math, MATH, true); | ||
@@ -212,3 +192,3 @@ // 21.1.2.2 String.fromCodePoint(...codePoints) | ||
// 22.1.2.1 Array.from(arrayLike, mapfn = undefined, thisArg = undefined) | ||
from: function(arrayLike, mapfn /* -> it */, thisArg /* = undefind */){ | ||
from: function(arrayLike, mapfn /* -> it */, that /* = undefind */){ | ||
var O = ES5Object(arrayLike) | ||
@@ -219,4 +199,4 @@ , result = new (generic(this, Array)) | ||
, length, f; | ||
if(mapping)f = ctx(mapfn, thisArg, 2); | ||
if($for && isIterable(O))$for(O).of(function(value){ | ||
if(mapping)f = ctx(mapfn, that, 2); | ||
if(isIterable(O))forOf(O, false, function(value){ | ||
result[index] = mapping ? f(value, index) : value; | ||
@@ -247,5 +227,4 @@ index++; | ||
var length = toLength(this.length) | ||
, index = toInteger(start) | ||
, index = max(getPositiveIndex(this, start), 0) | ||
, endPos; | ||
if(index < 0)index = max(index + length, 0); | ||
if(end === undefined)endPos = length; | ||
@@ -261,8 +240,16 @@ else { | ||
// 22.1.3.8 Array.prototype.find(predicate, thisArg = undefined) | ||
find: createArrayMethod(5), | ||
find: createArrayMethod(5), | ||
// 22.1.3.9 Array.prototype.findIndex(predicate, thisArg = undefined) | ||
findIndex: createArrayMethod(6) | ||
}); | ||
// 24.3.3 JSON [ @@toStringTag ] | ||
// 24.3.3 JSON[@@toStringTag] | ||
setToStringTag(global.JSON, 'JSON', true); | ||
}(isFinite); | ||
// 19.1.3.6 Object.prototype.toString() | ||
if(framework && TO_STRING_TAG){ | ||
tmp[TO_STRING_TAG] = 'x'; | ||
if(cof(tmp) != 'x')hidden(ObjectProto, TO_STRING, function(){ | ||
return '[object ' + classof(this) + ']'; | ||
}); | ||
} | ||
}(isFinite, {}); |
@@ -1,9 +0,2 @@ | ||
/** | ||
* setImmediate | ||
* https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/setImmediate/Overview.html | ||
* http://nodejs.org/api/timers.html#timers_setimmediate_callback_arg | ||
* Alternatives: | ||
* https://github.com/NobleJS/setImmediate | ||
* https://github.com/calvinmetcalf/immediate | ||
*/ | ||
// setImmediate shim | ||
// Node.js 0.9+ & IE10+ has setImmediate, else: | ||
@@ -53,3 +46,3 @@ isFunction(setImmediate) && isFunction(clearImmediate) || function(ONREADYSTATECHANGE){ | ||
} else if(isFunction(MessageChannel)){ | ||
channel = new MessageChannel(); | ||
channel = new MessageChannel; | ||
port = channel.port2; | ||
@@ -56,0 +49,0 @@ channel.port1.onmessage = listner; |
@@ -1,65 +0,41 @@ | ||
// Number.toInteger was part of the draft ECMAScript 6 specification, but has been removed | ||
$define(STATIC, NUMBER, {toInteger: toInteger}); | ||
$define(PROTO, NUMBER, { | ||
/** | ||
* Invoke function @ times and return array of results | ||
* Alternatives: | ||
* http://underscorejs.org/#times | ||
* http://sugarjs.com/api/Number/times | ||
* http://api.prototypejs.org/language/Number/prototype/times/ | ||
* http://mootools.net/docs/core/Types/Number#Number:times | ||
*/ | ||
times: function(mapfn /* = -> it */, thisArg /* = undefined */){ | ||
var number = +this | ||
, length = toLength(number) | ||
, result = Array(length) | ||
, i = 0 | ||
, f; | ||
if(isFunction(mapfn)){ | ||
f = ctx(mapfn, thisArg, 3); | ||
while(length > i)result[i] = f(i, i++, number); | ||
} else while(length > i)result[i] = i++; | ||
return result; | ||
}, | ||
random: function(lim /* = 0 */){ | ||
var a = +this | ||
, b = lim == undefined ? 0 : +lim | ||
, m = min(a, b); | ||
return random() * (max(a, b) - m) + m; | ||
!function(){ | ||
$define(PROTO + FORCED, NUMBER, { | ||
random: function(lim /* = 0 */){ | ||
var a = +this | ||
, b = lim == undefined ? 0 : +lim | ||
, m = min(a, b); | ||
return random() * (max(a, b) - m) + m; | ||
} | ||
}); | ||
function NumberIterator(iterated){ | ||
set(this, ITER, {l: toLength(iterated), i: 0}); | ||
} | ||
}); | ||
$define(STATIC, MATH, { | ||
randomInt: function(lim1 /* = 0 */, lim2 /* = 0 */){ | ||
var a = toInteger(lim1) | ||
, b = toInteger(lim2) | ||
, m = min(a, b); | ||
return floor(random() * (max(a, b) + 1 - m) + m); | ||
} | ||
}); | ||
/** | ||
* Math functions in Number.prototype | ||
* Alternatives: | ||
* http://sugarjs.com/api/Number/math | ||
* http://mootools.net/docs/core/Types/Number#Number-Math | ||
*/ | ||
$define(PROTO, NUMBER, turn.call( | ||
// IE... getNames(Math) | ||
array( | ||
// ES3: | ||
'round,floor,ceil,abs,sin,asin,cos,acos,tan,atan,exp,sqrt,max,min,pow,atan2,' + | ||
// ES6: | ||
'acosh,asinh,atanh,cbrt,clz32,cosh,expm1,hypot,imul,log1p,log10,log2,sign,sinh,tanh,trunc,' + | ||
// Core: | ||
'randomInt' | ||
), | ||
function(memo, key){ | ||
var fn = Math[key]; | ||
if(fn)memo[key] = function(/* ...args */){ | ||
// ie8- convert `this` to object -> convert it to number | ||
var args = [+this] | ||
, i = 0; | ||
while(arguments.length > i)args.push(arguments[i++]); | ||
return invoke(fn, args); | ||
} | ||
}, {} | ||
)); | ||
createIterator(NumberIterator, NUMBER, function(){ | ||
var iter = this[ITER] | ||
, i = iter.i++; | ||
return i < iter.l ? createIterResultObject(0, i) : createIterResultObject(1); | ||
}); | ||
defineIterator(Number, NUMBER, function(){ | ||
return new NumberIterator(this); | ||
}); | ||
$define(PROTO + FORCED, NUMBER, turn.call( | ||
array( | ||
// ES3: | ||
'round,floor,ceil,abs,sin,asin,cos,acos,tan,atan,exp,sqrt,max,min,pow,atan2,' + | ||
// ES6: | ||
'acosh,asinh,atanh,cbrt,clz32,cosh,expm1,hypot,imul,log1p,log10,log2,sign,sinh,tanh,trunc' | ||
), | ||
function(memo, key){ | ||
var fn = Math[key]; | ||
if(fn)memo[key] = function(/* ...args */){ | ||
// ie9- dont support strict mode & convert `this` to object -> convert it to number | ||
var args = [+this] | ||
, i = 0; | ||
while(arguments.length > i)args.push(arguments[i++]); | ||
return invoke(fn, args); | ||
} | ||
}, {} | ||
)); | ||
}(); |
!function(){ | ||
var getSymbols = Object.getOwnPropertySymbols | ||
, getPropertyKeys = getSymbols | ||
? function(it){ | ||
return getNames(it).concat(getSymbols(it)); | ||
} | ||
: getNames; | ||
// http://wiki.ecmascript.org/doku.php?id=strawman:extended_object_api | ||
// https://gist.github.com/WebReflection/9353781 | ||
function getOwnPropertyDescriptors(object){ | ||
var result = {} | ||
, keys = getPropertyKeys(object) | ||
function define(target, mixin){ | ||
var keys = ownKeys(ES5Object(mixin)) | ||
, length = keys.length | ||
, i = 0 | ||
, key; | ||
while(length > i)result[key = keys[i++]] = getOwnDescriptor(object, key); | ||
return result; | ||
} | ||
$define(STATIC, OBJECT, { | ||
isPrototype: ctx(call, ObjectProto.isPrototypeOf, 2), | ||
getOwnPropertyKeys: getPropertyKeys, | ||
// http://wiki.ecmascript.org/doku.php?id=harmony:extended_object_api | ||
getPropertyDescriptor: function(object, key){ | ||
var O = object; | ||
if(key in O)do { | ||
if(has(O, key))return getOwnDescriptor(O, key); | ||
} while(O = getPrototypeOf(O)); | ||
}, | ||
// http://wiki.ecmascript.org/doku.php?id=strawman:extended_object_api | ||
// ES7 : http://esdiscuss.org/topic/april-8-2014-meeting-notes#content-1 | ||
getOwnPropertyDescriptors: getOwnPropertyDescriptors, | ||
/** | ||
* Shugar for Object.create | ||
* Alternatives: | ||
* http://lodash.com/docs#create | ||
*/ | ||
make: function(proto, props){ | ||
return assign(create(proto), props); | ||
}, | ||
/** | ||
* 19.1.3.15 Object.mixin ( target, source ) | ||
* Removed in Draft Rev 22, January 20, 2014 | ||
* http://esdiscuss.org/topic/november-19-2013-meeting-notes#content-1 | ||
*/ | ||
define: function(target, source){ | ||
return defineProperties(target, getOwnPropertyDescriptors(source)); | ||
}, | ||
// ~ ES7 : http://esdiscuss.org/topic/april-8-2014-meeting-notes#content-1 | ||
values: createObjectToArray(false), | ||
// ~ ES7 : http://esdiscuss.org/topic/april-8-2014-meeting-notes#content-1 | ||
entries: createObjectToArray(true), | ||
, i = 0, key; | ||
while(length > i)defineProperty(target, key = keys[i++], getOwnDescriptor(mixin, key)); | ||
return target; | ||
}; | ||
$define(STATIC + FORCED, OBJECT, { | ||
isObject: isObject, | ||
classof: classof | ||
classof: classof, | ||
define: define, | ||
make: function(proto, mixin){ | ||
return define(create(proto), mixin); | ||
} | ||
}); | ||
}(); |
// ~ES7 : https://gist.github.com/kangax/9698100 | ||
$define(STATIC, REGEXP, { | ||
escape: createEscaper(/([\\\-[\]{}()*+?.,^$|])/g, '\\$1', true) | ||
escape: createReplacer(/([\\\-[\]{}()*+?.,^$|])/g, '\\$1', true) | ||
}); |
!function(){ | ||
var escapeHTMLDict = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
"'": ''' | ||
} | ||
, unescapeHTMLDict = turn.call(getKeys(escapeHTMLDict), function(memo, key){ | ||
memo[escapeHTMLDict[key]] = key; | ||
}, {}); | ||
$define(PROTO, STRING, { | ||
escapeHTML: createEscaper(/[&<>"']/g, escapeHTMLDict), | ||
unescapeHTML: createEscaper(/&(?:amp|lt|gt|quot|apos);/g, unescapeHTMLDict) | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
"'": ''' | ||
}, unescapeHTMLDict = {}, key; | ||
for(key in escapeHTMLDict)unescapeHTMLDict[escapeHTMLDict[key]] = key; | ||
$define(PROTO + FORCED, STRING, { | ||
escapeHTML: createReplacer(/[&<>"']/g, escapeHTMLDict), | ||
unescapeHTML: createReplacer(/&(?:amp|lt|gt|quot|apos);/g, unescapeHTMLDict) | ||
}); | ||
}(); |
@@ -1,21 +0,13 @@ | ||
/** | ||
* ie9- setTimeout & setInterval additional parameters fix | ||
* http://www.w3.org/TR/html5/webappapis.html#timers | ||
* http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#timers | ||
*/ | ||
!function(navigator){ | ||
// ie9- setTimeout & setInterval additional parameters fix | ||
!function(MSIE){ | ||
function wrap(set){ | ||
return function(fn, time /*, ...args */){ | ||
return set(invoke(part, slice.call(arguments, 2), isFunction(fn) ? fn : Function(fn)), time || 1); | ||
} | ||
return MSIE ? function(fn, time /*, ...args */){ | ||
return set(invoke(part, slice.call(arguments, 2), isFunction(fn) ? fn : Function(fn)), time); | ||
} : set; | ||
} | ||
$define(GLOBAL + BIND + FORCED * MSIE, { | ||
setTimeout: setTimeout = wrap(setTimeout), | ||
setInterval: wrap(setInterval) | ||
}); | ||
// ie9- dirty check | ||
if(navigator && /MSIE .\./.test(navigator.userAgent)){ | ||
setTimeout = wrap(setTimeout); | ||
setInterval = wrap(setInterval); | ||
} | ||
$define(GLOBAL + BIND + FORCED * !isNative(setTimeout), { | ||
setTimeout: setTimeout, | ||
setInterval: setInterval | ||
}); | ||
}(global.navigator); | ||
}(!!navigator && /MSIE .\./.test(navigator.userAgent)); |
@@ -17,3 +17,3 @@ // Karma configuration | ||
files: [ | ||
'../core.js', | ||
'../client/core.js', | ||
'../tests/tests.js' | ||
@@ -20,0 +20,0 @@ ], |
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
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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 too big to display
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
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
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
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
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
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
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
849582
65
17153
202
1