Socket
Socket
Sign inDemoInstall

es5-ext

Package Overview
Dependencies
0
Maintainers
0
Versions
83
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

lib/Function/bind.js

3

lib/Function/call.js

@@ -1,2 +0,3 @@

// f.call shortcut
// Return binded f.call to f
// call(f)(args…) =def f.call(args)

@@ -3,0 +4,0 @@ 'use strict';

// Returns a function that, applied to an argument list arg2, applies the
// underlying function to args ++ arg2.
// f.curry(args1…)(args2…) =def f(args1…, args2…)
// curry(f, args1…)(args2…) =def f(args1…, args2…)
//

@@ -9,4 +9,4 @@ // inspired by: http://osteele.com/sources/javascript/functional/

var toArray = require('../Array/toArray');
var slice = require('../Array/slice');
var toArray = require('../List/toArray').call
, slice = require('../List/slice').call;

@@ -13,0 +13,0 @@ module.exports = function (f) {

@@ -9,9 +9,8 @@ // Returns a function that swaps its first two arguments before passing them to

var a;
module.exports = function (f) {
return function () {
a = arguments[0];
arguments[0] = arguments[1]; arguments[1] = a;
return function (a, b) {
var x = a;
a = b; b = x;
return f.apply(this, arguments);
};
};
'use strict';
exports.K = require('./K');
exports.S = require('./S');
exports.bindMethods = require('./bindMethods');
exports.bind = require('./bind');
exports.call = require('./call');
exports.curry = require('./curry');
exports.dscope = require('./dscope');
exports.flip = require('./flip');
exports.functionalize = require('./functionalize');
exports.inherit = require('./inherit');
exports.invoke = require('./invoke');
exports.isFunction = require('./isFunction');
exports.k = require('./k');
exports.s = require('./s');
exports.sequence = require('./sequence');
// Returns a function that takes an object as an argument, and applies object's
// methodName method to arguments.
// invoke(name)(object, args…) =def object[name](args…)
// name method to arguments.
// invoke(name, args…)(object, args2…) =def object[name](args… args2…)
//

@@ -9,9 +9,9 @@ // inspired by: http://osteele.com/sources/javascript/functional/

var slice = require('../Array/slice');
var slice = require('../List/slice').call;
module.exports = function (methodName) {
module.exports = function (name) {
var args = slice(arguments, 1);
return function (obj) {
return obj[methodName].apply(obj, args.concat(slice(arguments, 1)));
return obj[name].apply(obj, args.concat(slice(arguments, 1)));
};
};

@@ -8,7 +8,10 @@ // Same as compose, except applies the functions in argument-list order.

var toArray = require('../Array/toArray');
var bind = require('./bind')
, toArray = require('../List/toArray').call
var f = function (result, method) {
, f;
f = bind(function (result, method) {
return [method.apply(this, result)];
};
});

@@ -18,4 +21,4 @@ module.exports = function () {

return function () {
return methods.reduce(f.bind(this), arguments)[0];
return methods.reduce(f(this), arguments)[0];
};
};

@@ -5,2 +5,4 @@ // Global object

module.exports = ('indirect', eval)('this');
var indirectEval = eval;
module.exports = indirectEval('this');

@@ -6,4 +6,4 @@ 'use strict';

exports.Array = require('./Array');
exports.Function = require('./Function');
exports.Array = require('./List');
exports.Object = require('./Object');
// Merge object properties of given object into one object
// elevate({ a: { b: 1, c: 1 }, d: { e: 1, f: 1 } })
// elevate.call({ a: { b: 1, c: 1 }, d: { e: 1, f: 1 } })
// =def { b: 1, c: 1, e: 1, f: 1 }

@@ -7,11 +7,11 @@

var curry = require('../Function/curry')
var f = require('../Function/functionalize')
, sequence = require('../Function/sequence')
, get = require('./get')
, merge = require('./merge');
, pluck = require('./pluck').bind
, merge = require('./merge').bind;
module.exports = function (obj, result) {
module.exports = f(function (result) {
result = result || {};
Object.keys(obj).forEach(sequence(get(obj), curry(merge, result)));
Object.keys(this).forEach(sequence(pluck(this), merge(result)));
return result;
};
});
'use strict';
exports.bindMethods = require('./bindMethods');
exports.elevate = require('./elevate');
exports.get = require('./get');
exports.extend = require('./extend');
exports.isObject = require('./isObject');

@@ -9,2 +10,3 @@ exports.isPlainObject = require('./isPlainObject');

exports.merge = require('./merge');
exports.pluck = require('./pluck');
exports.set = require('./set');

@@ -11,0 +13,0 @@ exports.setTrue = require('./setTrue');

// Whether object is plain object.
// Its protototype is Object.prototype and it is not host object
// Its protototype should be Object.prototype and it cannot be host object.
'use strict';
var call = require('../Function/call');
var f = require('../Function/functionalize')
, call = require('../Function/call')
var id = {}.toString();
var toString = call(Object.prototype.toString);
, id, toString;
module.exports = function (obj) {
return !!(obj &&
(typeof obj === "object") &&
(Object.getPrototypeOf(obj) === Object.prototype) &&
(toString(obj) === id));
};
id = {}.toString();
toString = call(Object.prototype.toString);
module.exports = f(function () {
return !!(this &&
(typeof this === "object") &&
(Object.getPrototypeOf(this) === Object.prototype) &&
(toString(this) === id));
});
// Returns a function that for given key assings chosen object property value to
// same property of other object
// link(a, b)(k) =def a[k]=b[k]
// link.call(a, b)(k) =def a[k]=b[k]
'use strict';
module.exports = function (a, b) {
return function (key) {
return a[key] = b[key];
};
};
var f = require('../Function/functionalize');
module.exports = f(function (b, k) {
return (this[k] = b[k]);
});

@@ -5,7 +5,8 @@ // Merge properties of one object into other

var link = require('./link');
var f = require('../Function/functionalize')
, link = require('./link').bind;
module.exports = function (a, b) {
Object.keys(b).forEach(link(a, b));
return a;
};
module.exports = f(function (b) {
Object.keys(b).forEach(link(this, b));
return this;
});
// Return function that sets value to key property for given object
// set(o)(k, v) =def o[k]=v
// set.call(o)(k, v) =def o[k]=v
'use strict';
module.exports = function (obj) {
return function (key, value) {
return obj[key] = value;
};
};
var f = require('../Function/functionalize');
module.exports = f(function (key, value) {
return (this[key] = value);
});
// Return function that sets true to key property for given object
// setTrue(o)(k) =def o[k]=true
// setTrue.call(o)(k) =def o[k]=true
'use strict';
module.exports = function (obj) {
return function (key) {
obj[key] = true;
};
};
var f = require('../Function/functionalize');
module.exports = f(function (key) {
this[key] = true;
});
// Return function that sets key property of given object to given value
// setValue(o, v)(k) =def o[k]=v
// setValue.call(o, v)(k) =def o[k]=v
'use strict';
module.exports = function (obj, value) {
return function (key) {
obj[key] = value;
};
};
var f = require('../Function/functionalize');
module.exports = f(function (value, key) {
this[key] = value;
});

@@ -1,9 +0,10 @@

// Return array of object properties values
// Return array of object property values
'use strict';
var get = require('./get');
var f = require('../Function/functionalize')
, pluck = require('./pluck').bind;
module.exports = function (obj) {
return Object.keys(obj).map(get(obj));
};
module.exports = f(function () {
return Object.keys(this).map(pluck(this));
});

@@ -5,4 +5,4 @@ // List of EcmaScript 5th edition reserved keywords

var setTrue = require('./Object/setTrue')
, elevate = require('./Object/elevate');
var setTrue = require('./Object/setTrue').bind
, elevate = require('./Object/elevate').call;

@@ -9,0 +9,0 @@ // 7.6.1.1 Keywords

{
"name": "es5-ext",
"version": "0.1.0",
"version": "0.2.0",
"description": "ECMAScript5 extensions",
"keywords": ["ecmascript", "ecmascript5", "es5", "extension", "extensions"],
"keywords": ["ecmascript", "ecmascript5", "es5", "extensions", "addons", "extras", "javascript"],
"author": "Mariusz Nowak <medikoo+es5-ext@medikoo.com> (http://www.medikoo.com/)",

@@ -16,3 +16,8 @@ "main": "lib/index",

},
"scripts": { "test": "node test/run" }
"scripts": { "test": "node test/run" },
"devDependencies": {
"test": "0.1.x",
"expresso": "0.7.x",
"jslint": "0.1.x"
}
}

@@ -9,3 +9,3 @@ # es5-ext - ECMAScript5 extensions

Can be used in any environment that implements ES5.
In implementations that are stuck to ES3 it will work when shim (e.g. [es5-shim](https://github.com/kriskowal/es5-shim)) is introduced.
In implementations that are stuck to ES3 it will work with [es5-shim](https://github.com/kriskowal/es5-shim).

@@ -18,9 +18,11 @@ To use it with node:

Recommended way:
Recommended way is to require stuff you need individually:
var curry = require('es5-ext/lib/Function/curry');
var sequence = require('es5-ext/lib/Function/sequence')
, merge = require('es5-ext/lib/Object/merge').call;
curry(...);
sequence(...);
merge(...);
or less specific:
but you can grab whole packs:

@@ -32,3 +34,3 @@ var fnExt = require('es5-ext/lib/Function');

if you want to take them all:
and if you prefer take them all:

@@ -39,7 +41,7 @@ var ext = require('es5-ext');

ext.Function.sequence(...);
ext.Object.merge(...);
ext.Object.merge.call(...);
### Extensions
_For descriptions look into source files._
_For documentation look into source files._

@@ -49,7 +51,2 @@ * `global`

#### Array
* `Array.slice(obj[, begin[, end]])`
* `Array.toArray(obj)`
#### Function

@@ -60,24 +57,36 @@

* `Function.K(obj)`
* `Function.S(f, g)`
* `Function.bindMethods(obj[, scope])`
* `Function.bind(f)`
* `Function.call(f)`
* `Function.curry(f[, ...])`
* `Function.dscope(f, scope)`
* `Function.flip(f)`
* `Function.functionalize(f)`
* `Function.inherit(f, g)`
* `Function.invoke(methodName[, ...])`
* `Function.isFunction(x)`
* `Function.k(x)`
* `Function.s(f, g)`
* `Function.sequence(f[, ...])`
#### List
Extensions for Array-like objects
* `List.slice([begin[, end]])`
* `List.toArray()`
#### Object
* `Object.elevate(obj[, res])`
* `Object.get(obj)`
* `Object.bindMethods([p])`
* `Object.elevate([p])`
* `Object.extend(o)`
* `Object.isObject(x)`
* `Object.isPlainObject(x)`
* `Object.link(obja, objb)`
* `Object.merge(target, source)`
* `Object.set(obj)`
* `Object.setTrue(obj)`
* `Object.setValue(obj, value)`
* `Object.values(obj)`
* `Object.isPlainObject()`
* `Object.link(p)`
* `Object.merge(p)`
* `Object.pluck(name)`
* `Object.set()`
* `Object.setTrue()`
* `Object.setValue(value)`
* `Object.values()`

@@ -88,2 +97,6 @@ ## Tests

$ npm test
$ make test
Tests with coverage report:
$ make test-cov
'use strict';
var f = require('Function/call')
var fn = require('Function/call')

@@ -14,3 +14,3 @@ , a, b, t;

"Function.call": function () {
assert.equal(f(a)(b, 'a', 'b'), 7, this);
assert.equal(fn(a)(b, 'a', 'b'), 7, this);
}

@@ -17,0 +17,0 @@ }).forEach(function (m) {

'use strict';
var f = require('Function/curry')
, toArray = require('Array/toArray')
var fn = require('Function/curry')
, toArray = require('List/toArray').call

@@ -14,3 +14,3 @@ , a, t;

"Function.curry": function () {
assert.equal(f(a, 1)(2, 3).toString(), [1, 2, 3].toString(), this);
assert.equal(fn(a, 1)(2, 3).toString(), [1, 2, 3].toString(), this);
}

@@ -17,0 +17,0 @@ }).forEach(function (m) {

'use strict';
var f = require('Function/flip')
, toArray = require('Array/toArray')
var fn = require('Function/flip')
, toArray = require('List/toArray').call

@@ -14,3 +14,3 @@ , a, t;

"Function.flip": function () {
assert.equal(f(a)(1, 2, 3).toString(), [2, 1, 3].toString(), this);
assert.equal(fn(a)(1, 2, 3).toString(), [2, 1, 3].toString(), this);
}

@@ -17,0 +17,0 @@ }).forEach(function (m) {

'use strict';
['K', 'S', 'bindMethods', 'call', 'curry', 'flip', 'invoke', 'isFunction',
'sequence'].forEach(function (mod) {
mod = require('./' + mod);
['bind', 'call', 'curry', 'dscope', 'flip', 'functionalize', 'inherit',
'invoke', 'isFunction', 'k', 's', 'sequence'].forEach(function (name) {
var mod = require('./' + name);
Object.keys(mod).forEach(function (key) {
if (exports[key]) {
assert.fail("Test name '" + key + "' already taken");
assert.fail("Test name '" + key + "' used in '" + name +
"' already taken");
return;

@@ -14,5 +15,1 @@ }

});
if (module == require.main) {
require('test').run(exports);
}
'use strict';
var f = require('Function/invoke')
, K = require('Function/K')
var fn = require('Function/invoke')
, k = require('Function/k')
, a, b, t;
a = { b: K('c')};
a = { b: k('c')};
Object.keys(t = {
"Function.invoke": function () {
assert.equal(f('b')(a), 'c', this);
assert.equal(fn('b')(a), 'c', this);
}

@@ -14,0 +14,0 @@ }).forEach(function (m) {

'use strict';
var f = require('Function/isFunction')
var fn = require('Function/isFunction')

@@ -11,6 +11,6 @@ , a, t;

"Function.isFunction: function is function": function () {
assert.equal(f(function () {}), true, this);
assert.equal(fn(function () {}), true, this);
},
"Function.isFunction: plain object is not function": function () {
assert.equal(f(a), false, this);
assert.equal(fn(a), false, this);
}

@@ -17,0 +17,0 @@ }).forEach(function (m) {

'use strict';
var f = require('Function/sequence')
var fn = require('Function/sequence')
, a, b, c, t;
a = function () {
return ['a', arguments.length, arguments[0], arguments[1]];
a = function (a, b) {
return ['a', arguments.length, a, b];
};
b = function () {
return ['b', arguments.length].concat(arguments[0]);
b = function (a) {
return ['b', arguments.length].concat(a);
};
c = function () {
return ['c', arguments.length].concat(arguments[0]);
c = function (a) {
return ['c', arguments.length].concat(a);
};

@@ -19,3 +19,4 @@

"Function.sequence": function () {
assert.equal(f(a, b, c)(1, 2).toString(), ['c', 1, 'b', 1, 'a', 2, 1, 2], this);
assert.equal(fn(a, b, c)(1, 2).toString(),
['c', 1, 'b', 1, 'a', 2, 1, 2], this);
}

@@ -22,0 +23,0 @@ }).forEach(function (m) {

@@ -9,3 +9,3 @@ 'use strict';

"Global is an object": function () {
assert.ok(o && typeof o == 'object', this);
assert.ok(o && typeof o === 'object', this);
}

@@ -12,0 +12,0 @@ }).forEach(function (m) {

'use strict';
['global', 'reserved', 'Array', 'Function', 'Object'].forEach(function (mod) {
['global', 'reserved', 'Function', 'List', 'Object'].forEach(function (mod) {
mod = require('./' + mod);

@@ -5,0 +5,0 @@ Object.keys(mod).forEach(function (key) {

'use strict';
var f = require('Object/elevate')
var fn = require('Object/elevate').call
, o, t;
o = f({ a: { aa: 1, ab: 2 }, b: { ba: 3, bb: 4 } });
o = fn({ a: { aa: 1, ab: 2 }, b: { ba: 3, bb: 4 } });

@@ -9,0 +9,0 @@ Object.keys(t = {

'use strict';
['elevate', 'get', 'isObject', 'isPlainObject', 'link', 'merge', 'set',
'setTrue', 'setValue', 'values'].forEach(function (mod) {
['bindMethods', 'elevate', 'extend', 'isObject', 'isPlainObject', 'link',
'merge', 'pluck', 'set', 'setTrue', 'setValue', 'values']
.forEach(function (mod) {
mod = require('./' + mod);

@@ -14,5 +15,1 @@ Object.keys(mod).forEach(function (key) {

});
if (module == require.main) {
require('test').run(exports);
}
'use strict';
var f = require('Object/isObject')
var fn = require('Object/isObject')

@@ -9,12 +9,12 @@ , t;

"Object.isObject: object is object": function () {
assert.equal(f({}), true, this);
assert.equal(fn({}), true, this);
},
"Object.isObject: null is not object": function () {
assert.equal(f(null), false, this);
assert.equal(fn(null), false, this);
},
"Object.isObject: primitive is not object": function () {
assert.equal(f('string'), false, this);
assert.equal(fn('string'), false, this);
},
"Object.isObject: function is not object": function () {
assert.equal(f(function () {}), false, this);
assert.equal(fn(function () {}), false, this);
}

@@ -21,0 +21,0 @@ }).forEach(function (m) {

'use strict';
var f = require('Object/isPlainObject')
var fn = require('Object/isPlainObject').call

@@ -9,24 +9,24 @@ , t;

"Object.isPlainObject: empty {} is plain object": function () {
assert.equal(f({}), true, this);
assert.equal(fn({}), true, this);
},
"Object.isPlainObject: {} with property is plain object": function () {
assert.equal(f({ a: true }), true, this);
assert.equal(fn({ a: true }), true, this);
},
"Object.isPlainObject: {} with any property keys is plain object":
function () {
assert.equal(f({ prototype: 1, constructor: 2, __proto__: 3 }),
assert.equal(fn({ 'prototype': 1, 'constructor': 2, '__proto__': 3 }),
true, this);
},
"Object.isPlainObject: null is not plain object": function () {
assert.equal(f(null), false, this);
assert.equal(fn(null), false, this);
},
"Object.isPlainObject: primitive is not plain object": function () {
assert.equal(f('string'), false, this);
assert.equal(fn('string'), false, this);
},
"Object.isPlainObject: function is not plain object": function () {
assert.equal(f(function () {}), false, this);
assert.equal(fn(function () {}), false, this);
},
"Object.isPlainObject: object whose prototype is not Object.prototype is not plain object":
function () {
assert.equal(f(Object.create({})), false, this);
assert.equal(fn(Object.create({})), false, this);
}

@@ -33,0 +33,0 @@ }).forEach(function (m) {

'use strict';
var f = require('Object/link')
var fn = require('Object/link').call
, a, b, t;
a = {}, b = { a: 2 };
f(a, b)('a');
a = {};
b = { a: 2 };
fn(a, b, 'a');
Object.keys(t = {

@@ -11,0 +13,0 @@ "Object.link": function () {

'use strict';
var f = require('Object/merge')
var fn = require('Object/merge').call

@@ -9,3 +9,3 @@ , a, b, t;

b = { a: 1, b: 4, c: 3 };
f(a, b);
fn(a, b);

@@ -12,0 +12,0 @@ Object.keys(t = {

'use strict';
var f = require('Object/set')
var fn = require('Object/set').call

@@ -8,3 +8,3 @@ , a, t;

a = {};
f(a)('b', 2);
fn(a, 'b', 2);

@@ -11,0 +11,0 @@ Object.keys(t = {

'use strict';
var f = require('Object/setTrue')
var fn = require('Object/setTrue').call

@@ -8,3 +8,3 @@ , a, t;

a = {};
f(a)('b');
fn(a, 'b');

@@ -11,0 +11,0 @@ Object.keys(t = {

'use strict';
var f = require('Object/setValue')
var fn = require('Object/setValue').call

@@ -8,3 +8,3 @@ , a, t;

a = {};
f(a, 2)('b');
fn(a, 2, 'b');

@@ -11,0 +11,0 @@ Object.keys(t = {

'use strict';
var f = require('Object/values')
var fn = require('Object/values').call

@@ -11,3 +11,3 @@ , a, t;

"Object.values": function () {
assert.equal(f(a).sort().toString(), ['d', 'e', 'f'].toString(), this);
assert.equal(fn(a).sort().toString(), ['d', 'e', 'f'].toString(), this);
}

@@ -14,0 +14,0 @@ }).forEach(function (m) {

'use strict';
var exec = require('child_process').exec
var tests;
, run, install;
require('./setup');
run = function () {
require('./setup');
var tests = require('./');
require('test').run({
'test es5-ext': function (assert) {
(1, eval)('this').assert = assert;
Object.keys(tests).forEach(function (key) {
tests[key]();
});
}
});
};
tests = require('./');
install = function (name, callback) {
try {
require(name);
setTimeout(callback, 0);
} catch (e) {
console.log("installing '" + name + "' module ...");
exec('npm install ' + name + '@latest', function (error, stdout, stderr) {
if (stdout) {
console.log(stdout.trim());
}
if (stderr) {
console.error(stderr.trim());
}
if (error !== null) {
console.error('exec error: ' + error);
}
callback(error || stderr || null);
require('test').run({
'test es5-ext': function (assert) {
var indirectEval = eval;
indirectEval('this').assert = assert;
Object.keys(tests).forEach(function (key) {
tests[key]();
});
}
};
install('test', function (err) {
if (err) {
return;
}
run();
});
'use strict';
var global = ('indirect', eval)('this');
var indirectEval = eval;
var global = indirectEval('this');

@@ -9,2 +10,2 @@ global.assert = require('assert');

// move on expresso
exports['ignore'] = function () {};
exports.ignore = function () {};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc