Socket
Socket
Sign inDemoInstall

ramda

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ramda - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

bower.json

2

Gruntfile.js

@@ -39,4 +39,2 @@ module.exports = function(grunt) {

evil: true,
globals: {
}
}

@@ -43,0 +41,0 @@ },

@@ -8,2 +8,7 @@ {

"web": "http://buzzdecafe.com"
},
{
"name": "Scott Sauyet",
"email": "scott@sauyet.com",
"web": "http://fr.umio.us"
}

@@ -13,3 +18,3 @@ ],

"description": "A practical functional library for Javascript programmers.",
"version": "0.1.5",
"version": "0.2.0",
"homepage": "https://www.github.com/CrossEye/ramda",

@@ -34,15 +39,5 @@ "license": "MIT",

"grunt-mocha-test": "~0.5.0",
"grunt-istanbul": "~0.2.4"
},
"extraDevDependencies -- if we want to use Gulp": {
"gulp-rename": "~0.2.1",
"gulp-jshint": "~1.3.2",
"gulp-uglify": "~0.1.0",
"gulp-mocha": "~0.1.0",
"gulp-clean": "~0.1.2",
"gulp-util": "~2.2.0",
"gulp-header": "godaddy/gulp-header",
"gulp-istanbul": "~0.1.0",
"moment": "~2.5.0"
"benchmark": "~1.0.0",
"lodash": "latest"
}
}

@@ -6,4 +6,4 @@ Project Ramda

[![Build Status](https://travis-ci.org/CrossEye/ramda.svg?branch=master)](https://travis-ci.org/CrossEye/ramda)
Goals

@@ -126,3 +126,5 @@ -----

Thanks to [J. C. Phillipps](http://www.jcphillipps.com) for the Ramda logo.
Ramda logo artwork © 2014 J. C. Phillipps. Licensed Creative Commons
[CC BY-NC-SA 3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/).

@@ -22,2 +22,6 @@ var assert = require('assert');

});
it('should be aliased by `constant`', function() {
assert.strictEqual(Lib.constant, always);
});
});

@@ -24,0 +28,0 @@

@@ -20,17 +20,2 @@ var assert = require("assert");

describe('cloneDeep', function() {
var cloneDeep = Lib.cloneDeep;
it('returns a copy of an array', function() {
assert.deepEqual(cloneDeep([1,2,3,4,5]), [1,2,3,4,5]);
});
it('does not copy objects in the array by reference', function() {
var o1 = {x: 1};
var o2 = {x: 2};
var o3 = {x: 3};
var c = cloneDeep([o1, o2, o3]);
assert.notEqual(c[0], o1);
});
});

@@ -41,2 +41,3 @@ var assert = require('assert');

assert.deepEqual(prepend('x', ['y', 'z']), ['x', 'y', 'z']);
assert.deepEqual(prepend(['a', 'z'], ['x', 'y']), [['a', 'z'], 'x', 'y']);
});

@@ -50,2 +51,3 @@ });

assert.deepEqual(append('z', ['x', 'y']), ['x', 'y', 'z']);
assert.deepEqual(append(['a', 'z'], ['x', 'y']), ['x', 'y', ['a', 'z']]);
});

@@ -52,0 +54,0 @@ });

@@ -87,10 +87,2 @@ var assert = require("assert");

it('should stop when the list is exhausted', function() {
assert.deepEqual(take(5, ['a', 'b', 'c']), ['a', 'b', 'c']);
});
it('should correctly report the length when it take fewer than expected', function() {
assert.equal(take(5, ['a', 'b', 'c']).length, 3);
});
it('should be automatically curried', function() {

@@ -110,2 +102,7 @@ var take3 = take(3);

it('should start at the right arg and acknowledges undefined', function() {
assert.deepEqual(takeWhile(function(x) { assert.ok(false); }, []), []);
assert.deepEqual(takeWhile(function(x) {return x !== void 0;}, [1, 3, void 0, 5, 7]), [1, 3]);
});
it('should be automatically curried', function() {

@@ -144,2 +141,9 @@ var takeUntil7 = takeWhile(function(x) {return x != 7;});

it('should start at the right arg and acknowledges undefined', function() {
assert.deepEqual(skipUntil(function(x) {
assert.ok(false);
}, []), []);
assert.deepEqual(skipUntil(function(x) {return x === void 0;}, [1, 3, void 0, 5, 7]), [void 0, 5, 7]);
});
it('should be automatically curried', function() {

@@ -146,0 +150,0 @@ var skipUntil7 = skipUntil(function(x) {return x === 7;});

@@ -43,8 +43,30 @@ var assert = require("assert");

it("returns -1 when no element satisfies the predicate", function() {
assert.equal(findIndex(even, 'zing'), -1);
});
});
describe('findLast', function() {
var findLast = Lib.findLast;
var obj1 = {x: 100};
var obj2 = {x: 200};
var a = [11, 10, 9, 'cow', obj1, 8, 7, 100, 200, 300, obj2, 4, 3, 2, 1, 0];
var even = function(x) { return x % 2 === 0; };
var gt100 = function(x) { return x > 100; };
var isStr = function(x) { return typeof x === "string"; };
var xGt100 = function(o) { return o && o.x > 100; };
it("returns the index of the last element that satisfies the predicate", function() {
assert.equal(findLast(even, a), 0);
assert.equal(findLast(gt100, a), 300);
assert.equal(findLast(isStr, a), 'cow');
assert.equal(findLast(xGt100, a), obj2);
});
it("returns `undefined` when no element satisfies the predicate", function() {
assert.equal(findIndex(even, 'zing'), undefined);
assert.equal(findLast(even, 'zing'), undefined);
});
});
describe('findLast', function() {
describe('findLastIndex', function() {
var findLastIndex = Lib.findLastIndex;

@@ -66,6 +88,6 @@ var obj1 = {x: 100};

it("returns `undefined` when no element satisfies the predicate", function() {
assert.equal(findLastIndex(even, 'zing'), undefined);
it("returns -1 when no element satisfies the predicate", function() {
assert.equal(findLastIndex(even, 'zing'), -1);
});
});

@@ -20,20 +20,2 @@ var assert = require('assert');

//describe('cycle', function() {
// var cycle = Lib.cycle;
// it('should return a function which cycles the arguments to the supplied function so that the first becomes last', function() {
// var f = function(a, b, c) {return a + ' ' + b + ' ' + c;};
// var g = cycle(f);
// var h = cycle(g);
// assert.equal(f('a', 'b', 'c'), 'a b c');
// assert.equal(g('a', 'b', 'c'), 'b c a');
// assert.equal(h('a', 'b', 'c'), 'c a b');
// });
//
// it('should return a curried function', function() {
// var f = function(a, b, c) {return a + ' ' + b + ' ' + c;};
// var g = cycle(f)('a');
// assert.equal(g('b', 'c'), 'b c a');
// });
//});
describe('once', function() {

@@ -113,3 +95,38 @@ var once = Lib.once;

});
});
describe('unary', function() {
var unary = Lib.unary;
it('should turn multiple-argument function into unary one', function() {
unary(function(x, y, z) {
assert.equal(arguments.length, 1);
assert.equal(typeof y, "undefined");
assert.equal(typeof z, "undefined");
})(10, 20, 30);
});
it('initial argument is passed through normally', function() {
unary(function(x, y, z) {
assert.equal(x, 10);
})(10, 20, 30);
});
});
describe('binary', function() {
var binary = Lib.binary;
it('should turn multiple-argument function into binary one', function() {
binary(function(x, y, z) {
assert.equal(arguments.length, 2);
assert.equal(typeof z, "undefined");
})(10, 20, 30);
});
it('initial arguments are passed through normally', function() {
binary(function(x, y, z) {
assert.equal(x, 10);
assert.equal(y, 20);
})(10, 20, 30);
});
});

@@ -8,8 +8,30 @@ var assert = require("assert");

var obj = {a: 100, b: [1,2,3], c: { x: 200, y: 300}, d: "D", e: null, f: (function(){}())};
it("returns an array of the given object's keys", function() {
function C() { this.a = 100; this.b = 200; }
C.prototype.x = function() { return "x"; };
C.prototype.y = "y";
var cobj = new C();
it("returns an array of the given object's own keys", function() {
assert.deepEqual(keys(obj), ['a','b','c','d','e','f']);
});
it("does not include the given object's prototype properties", function() {
assert.deepEqual(keys(cobj), ['a', 'b']);
});
});
describe("keysIn", function() {
var keysIn = Lib.keysIn;
var obj = {a: 100, b: [1,2,3], c: { x: 200, y: 300}, d: "D", e: null, f: (function(){}())};
function C() { this.a = 100; this.b = 200; }
C.prototype.x = function() { return "x"; };
C.prototype.y = "y";
var cobj = new C();
it("returns an array of the given object's keys", function() {
assert.deepEqual(keysIn(obj), ['a','b','c','d','e','f']);
});
it("includes the given object's prototype properties", function() {
assert.deepEqual(keysIn(cobj), ['a', 'b', 'x', 'y']);
});
});
describe("values", function() {

@@ -19,7 +41,30 @@ var values = Lib.values;

var undef;
function C() { this.a = 100; this.b = 200; }
C.prototype.x = function() { return "x"; };
C.prototype.y = "y";
var cobj = new C();
it("returns an array of the given object's values", function() {
assert.deepEqual(values(obj), [100,[1,2,3],{x: 200, y: 300},'D',null,undef]);
});
it("does not include the given object's prototype properties", function() {
assert.deepEqual(values(cobj), [100, 200]);
});
});
describe("valuesIn", function() {
var valuesIn = Lib.valuesIn;
var obj = {a: 100, b: [1,2,3], c: { x: 200, y: 300}, d: "D", e: null, f: (function(){}())};
function C() { this.a = 100; this.b = 200; }
C.prototype.x = function() { return "x"; };
C.prototype.y = "y";
var cobj = new C();
it("returns an array of the given object's values", function() {
assert.deepEqual(valuesIn(obj), [100,[1,2,3],{x: 200, y: 300},'D',null,undefined]);
});
it("includes the given object's prototype properties", function() {
assert.deepEqual(valuesIn(cobj), [100, 200, C.prototype.x, 'y']);
});
});

@@ -232,3 +232,3 @@ var assert = require("assert");

it('calculates the largest value of a list', function() {
it('calculates the smallest value of a list', function() {
assert.equal(min([2, 1, 2, 8, 6, 7, 5, 3, 0, 9]), 0);

@@ -245,15 +245,14 @@ assert.equal(min([7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]), 1);

describe('maxWith', function() {
var maxWith = Lib.maxWith;
var comparator = function(a, b) {return a.x - b.x;};
var maxWith = Lib.maxWith, prop = Lib.prop;
it('calculates the largest value of a list using the supplied comparator', function() {
assert.deepEqual(maxWith(comparator, [{x: 3, y: 1}, {x: 5, y: 10}, {x: -2, y: 0}]), {x: 5, y: 10});
assert.deepEqual(maxWith(prop('x'), [{x: 3, y: 1}, {x: 5, y: 10}, {x: -2, y: 0}]), {x: 5, y: 10});
});
it('returns null for the empty list', function() {
assert.equal(maxWith(comparator, []), null);
it('returns undefined for the empty list', function() {
assert.equal(maxWith(prop('x'), []), undefined);
});
it('is properly curried', function() {
var highestX = maxWith(comparator);
var highestX = maxWith(prop('x'));
assert.deepEqual(highestX([{x: 3, y: 1}, {x: 5, y: 10}, {x: -2, y: 0}]), {x: 5, y: 10});

@@ -264,17 +263,16 @@ });

describe('minWith', function() {
var minWith = Lib.minWith;
var comparator = function(a, b) {return a.x - b.x;};
var minWith = Lib.minWith, prop = Lib.prop;
it('calculates the largest value of a list using the supplied comparator', function() {
assert.deepEqual(minWith(comparator, [{x: 3, y: 1}, {x: 5, y: 10}, {x: -2, y: 0}]), {x: -2, y: 0});
it('calculates the smallest value of a list using the supplied comparator', function() {
assert.deepEqual(minWith(prop('x'), [{x: 3, y: 1}, {x: 5, y: 10}, {x: -2, y: 0}]), {x: -2, y: 0});
});
it('returns null for the empty list', function() {
assert.equal(minWith(comparator, []), null);
assert.equal(typeof(minWith(prop('x'), [])), "undefined");
});
it('is properly curried', function() {
var lowestX = minWith(comparator);
var lowestX = minWith(prop('x'));
assert.deepEqual(lowestX([{x: 3, y: 1}, {x: 5, y: 10}, {x: -2, y: 0}]), {x: -2, y: 0});
});
});
var assert = require('assert');
var Lib = require('./../ramda');
describe('prop', function() {
describe('prop', function () {
var prop = Lib.prop;
var fred = {name: 'Fred', age:23};
var fred = {name: 'Fred', age: 23};
it('should return a function that fetches the appropriate property', function() {
it('should return a function that fetches the appropriate property', function () {
var nm = prop('name');

@@ -14,3 +14,3 @@ assert.equal(typeof nm, 'function');

it('should be aliased by `get`', function() { // TODO: should it?
it('should be aliased by `get`', function () { // TODO: should it?
assert.equal(Lib.get('age')(fred), 23);

@@ -21,8 +21,12 @@ assert.strictEqual(Lib.get, prop);

describe('func', function() {
describe('func', function () {
var func = Lib.func;
it('should return a function that applies the appropriate function to the supplied object', function() {
var fred = {first: 'Fred', last: 'Flintstone', getName: function() {return this.first + ' ' + this.last;}};
var barney = {first: 'Barney', last: 'Rubble', getName: function() {return this.first + ' ' + this.last;}};
it('should return a function that applies the appropriate function to the supplied object', function () {
var fred = {first: 'Fred', last: 'Flintstone', getName: function () {
return this.first + ' ' + this.last;
}};
var barney = {first: 'Barney', last: 'Rubble', getName: function () {
return this.first + ' ' + this.last;
}};
var gName = func('getName');

@@ -34,5 +38,11 @@ assert.equal(typeof gName, 'function');

it('should apply additional arguments to the function', function() {
var Point = function(x, y) {this.x = x; this.y = y;};
Point.prototype.moveBy = function(dx, dy) {this.x += dx; this.y += dy;};
it('should apply additional arguments to the function', function () {
var Point = function (x, y) {
this.x = x;
this.y = y;
};
Point.prototype.moveBy = function (dx, dy) {
this.x += dx;
this.y += dy;
};
var p1 = new Point(10, 20);

@@ -47,7 +57,11 @@ var moveBy = func('moveBy');

// TODO: This needs a better home than objectBasics
describe('pluck', function() {
describe('pluck', function () {
var pluck = Lib.pluck;
var people = [{name: 'Fred', age: 23}, {name: 'Wilma', age: 21} , {name: 'Pebbles', age: 2}];
var people = [
{name: 'Fred', age: 23},
{name: 'Wilma', age: 21} ,
{name: 'Pebbles', age: 2}
];
it('should return a function that maps the appropriate property over an array', function() {
it('should return a function that maps the appropriate property over an array', function () {
var nm = pluck('name');

@@ -59,7 +73,7 @@ assert.equal(typeof nm, 'function');

describe('props', function() {
describe('props', function () {
var props = Lib.props;
var fred = {name: 'Fred', age: 23, feet: 'large'};
it('should return a function that fetches the appropriate properties from the initially supplied object', function() {
it('should return a function that fetches the appropriate properties from the initially supplied object', function () {
var p = props(fred);

@@ -72,12 +86,12 @@ assert.equal(p('name'), 'Fred');

describe('pick', function() {
describe('pick', function () {
var pick = Lib.pick;
var obj = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6};
it('should copy the named properties of an object to the new object', function() {
it('should copy the named properties of an object to the new object', function () {
assert.deepEqual(pick(['a', 'c', 'f'], obj), {a: 1, c: 3, f: 6});
});
it('should ignore properties not included', function() {
it('should ignore properties not included', function () {
assert.deepEqual(pick(['a', 'c', 'g'], obj), {a: 1, c: 3});
});
it('should be automatically curried', function() {
it('should be automatically curried', function () {
var copyAB = pick(['a', 'b']);

@@ -89,12 +103,12 @@ assert.deepEqual(copyAB(obj), {a: 1, b: 2});

describe('pickAll', function() {
describe('pickAll', function () {
var pickAll = Lib.pickAll;
var obj = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6};
it('should copy the named properties of an object to the new object', function() {
it('should copy the named properties of an object to the new object', function () {
assert.deepEqual(pickAll(['a', 'c', 'f'], obj), {a: 1, c: 3, f: 6});
});
it('should include properties not present on the input object', function() {
it('should include properties not present on the input object', function () {
assert.deepEqual(pickAll(['a', 'c', 'g'], obj), {a: 1, c: 3, g: undefined});
});
it('should be automatically curried', function() {
it('should be automatically curried', function () {
var copyAB = pickAll(['a', 'b']);

@@ -105,9 +119,9 @@ assert.deepEqual(copyAB(obj), {a: 1, b: 2});

describe('omit', function() {
describe('omit', function () {
var omit = Lib.omit;
var obj = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6};
it('should copy an object omitting the listed properties', function() {
it('should copy an object omitting the listed properties', function () {
assert.deepEqual(omit(['a', 'c', 'f'], obj), {b: 2, d: 4, e: 5});
});
it('should be automatically curried', function() {
it('should be automatically curried', function () {
var skipAB = omit(['a', 'b']);

@@ -118,70 +132,201 @@ assert.deepEqual(skipAB(obj), {c: 3, d: 4, e: 5, f: 6});

describe('eqProps', function() {
describe('eqProps', function () {
var eqProps = Lib.eqProps;
it('reports whether two objects have the same value for a given property', function() {
assert.equal(eqProps("name", {name: "fred", age: 10}, {name: "fred", age: 12}), true);
assert.equal(eqProps("name", {name: "fred", age: 10}, {name: "franny", age: 10}), false);
it('reports whether two objects have the same value for a given property', function () {
assert.equal(eqProps('name', {name: 'fred', age: 10}, {name: 'fred', age: 12}), true);
assert.equal(eqProps('name', {name: 'fred', age: 10}, {name: 'franny', age: 10}), false);
});
it('should be automatically curried', function() {
var sameName = eqProps("name");
assert.equal(sameName({name: "fred", age: 10}, {name: "fred", age: 12}), true);
it('should be automatically curried', function () {
var sameName = eqProps('name');
assert.equal(sameName({name: 'fred', age: 10}, {name: 'fred', age: 12}), true);
});
});
describe('where', function() {
describe('where', function () {
var where = Lib.where;
it("takes a spec and a test object and returns true if the test object satisfies the spec", function() {
it('takes a spec and a test object and returns true if the test object satisfies the spec', function () {
var spec = {x: 1, y: 2};
var test1 = {x: 0, y: 200};
var test2 = {x: 0, y: 10};
var test3 = {x: 1, y: 101};
var test4 = {x: 1, y: 2};
assert.equal(where(spec, test1), false);
assert.equal(where(spec, test2), false);
assert.equal(where(spec, test3), false);
assert.equal(where(spec, test4), true);
var spec = {x: 1, y: 2};
var test1 = {x: 0, y: 200};
var test2 = {x: 0, y: 10};
var test3 = {x: 1, y: 101};
var test4 = {x: 1, y: 2};
assert.equal(where(spec, test1), false);
assert.equal(where(spec, test2), false);
assert.equal(where(spec, test3), false);
assert.equal(where(spec, test4), true);
});
it("calls any functions in the spec against the test object value for that property", function() {
var spec = {
a: function(a, obj) {return a < obj.b + obj.c;},
b: function(b, obj) {return b < obj.a + obj.c;},
c: function(c, obj) {return c < obj.a + obj.b;}
};
var test1 = {a: 3, b: 4, c: 5};
var test2 = {a: 6, b: 8, c: 9};
var test3 = {a: 2, b: 8, c: 12};
var test4 = {a: 3, b: 11, c: 5};
it('calls any functions in the spec against the test object value for that property', function () {
var spec = {
a: function (a, obj) {
return a < obj.b + obj.c;
},
b: function (b, obj) {
return b < obj.a + obj.c;
},
c: function (c, obj) {
return c < obj.a + obj.b;
}
};
var test1 = {a: 3, b: 4, c: 5};
var test2 = {a: 6, b: 8, c: 9};
var test3 = {a: 2, b: 8, c: 12};
var test4 = {a: 3, b: 11, c: 5};
assert.equal(where(spec, test1), true);
assert.equal(where(spec, test2), true);
assert.equal(where(spec, test3), false);
assert.equal(where(spec, test4), false);
assert.equal(where(spec, test1), true);
assert.equal(where(spec, test2), true);
assert.equal(where(spec, test3), false);
assert.equal(where(spec, test4), false);
});
it("doesn't need the spec and the test object to have the same interface (the test object will have a superset of the specs properties)", function() {
var spec = {x: 100};
var test1 = {x: 20, y: 100, z: 100};
var test2 = {w: 1, x: 100, y: 100, z: 100};
it('does not need the spec and the test object to have the same interface (the test object will have a superset of the specs properties)', function () {
var spec = {x: 100};
var test1 = {x: 20, y: 100, z: 100};
var test2 = {w: 1, x: 100, y: 100, z: 100};
assert.equal(where(spec, test1), false);
assert.equal(where(spec, test2), true);
assert.equal(where(spec, test1), false);
assert.equal(where(spec, test2), true);
});
it('is false if the test object is null-ish', function () {
var spec = {x: 200};
var testN = null;
var testU = undefined;
var testF = false;
assert.equal(where(spec, testN), false);
assert.equal(where(spec, testU), false);
assert.equal(where(spec, testF), false);
});
it('matches specs that have undefined properties', function () {
var spec = {x: undefined};
var test1 = {};
var test2 = {x: null};
var test3 = {x: undefined};
var test4 = {x: 1};
assert.equal(where(spec, test1), false); // TODO: discuss Scott's objections
assert.equal(where(spec, test2), false);
assert.equal(where(spec, test3), true);
assert.equal(where(spec, test4), false);
});
it('is automatically curried', function () {
var predicate = where({x: 1, y: 2});
assert.equal(predicate({x: 1, y: 2, z: 3}), true);
assert.equal(predicate({x: 3, y: 2, z: 1}), false);
});
});
describe('mixin', function() {
var mixin = Lib.mixin;
describe('mixin', function () {
var mixin = Lib.mixin;
it('takes two objects, merges their own properties and returns a new object', function() {
var a = {w: 1, x: 2};
var b = {y: 3, z: 4};
assert.deepEqual(mixin(a, b), {w: 1, x: 2, y: 3, z: 4});
});
it('takes two objects, merges their own properties and returns a new object', function () {
var a = {w: 1, x: 2};
var b = {y: 3, z: 4};
assert.deepEqual(mixin(a, b), {w: 1, x: 2, y: 3, z: 4});
});
it('overrides properties in the first object with properties in the second object', function() {
var a = {w: 1, x: 2};
var b = {w: 100, y: 3, z: 4};
assert.deepEqual(mixin(a, b), {w: 100, x: 2, y: 3, z: 4});
});
it('overrides properties in the first object with properties in the second object', function () {
var a = {w: 1, x: 2};
var b = {w: 100, y: 3, z: 4};
assert.deepEqual(mixin(a, b), {w: 100, x: 2, y: 3, z: 4});
});
});
describe('pathWith', function() {
var pathWith = Lib.pathWith;
it("takes a function, a string path, and an object, and returns the value at that path or undefined.", function() {
var obj = {
a: {
b: {
c: 100,
d: 200
},
e: {
f: [100, 101, 102],
g: 'G'
},
h: 'H'
},
i: 'I',
j: ['J']
};
var everyThirdChar = function(str) {
var parts = [];
var i = -1;
while (++i < str.length) {
if (i % 3 === 0) {
parts.push(str.charAt(i));
}
}
return parts;
};
var path = 'axxbyyc';
assert.equal(pathWith(everyThirdChar, 'azsbt5c', obj), 100);
assert.equal(pathWith(everyThirdChar, '', obj), undefined);
assert.equal(pathWith(everyThirdChar, 'axxeaafaa1', obj), 101);
assert.equal(pathWith(everyThirdChar, 'j__0', obj), 'J');
assert.equal(pathWith(everyThirdChar, 'j__1', obj), undefined);
assert.equal(pathWith(everyThirdChar, 'azsbt5c', null), undefined);
});
});
describe('pathOn', function() {
var pathOn = Lib.pathOn;
it("takes a string separator, string path, and an object and returns the value at the path or undefined", function() {
var obj = {
a: {
b: {
c: 100,
d: 200
},
e: {
f: [100, 101, 102],
g: 'G'
},
h: 'H'
},
i: 'I',
j: ['J']
};
assert.equal(pathOn('|', 'a|b|c', obj), 100);
assert.equal(pathOn(' ', '', obj), undefined);
assert.equal(pathOn(' ', 'a e f 1', obj), 101);
assert.equal(pathOn('_', 'j_0', obj), 'J');
assert.equal(pathOn('~', 'j~1', obj), undefined);
assert.equal(pathOn('Z', 'aZbZc', null), undefined);
});
});
describe('path', function() {
var path = Lib.path;
it("takes a dot-delimited path and an object and returns the value at the path or undefined", function() {
var obj = {
a: {
b: {
c: 100,
d: 200
},
e: {
f: [100, 101, 102],
g: 'G'
},
h: 'H'
},
i: 'I',
j: ['J']
};
assert.equal(path('a.b.c', obj), 100);
assert.equal(path('', obj), undefined);
assert.equal(path('a.e.f.1', obj), 101);
assert.equal(path('j.0', obj), 'J');
assert.equal(path('j.1', obj), undefined);
assert.equal(path('a.b.c', null), undefined);
});
});

@@ -22,7 +22,13 @@ var assert = require("assert");

describe('zip', function() {
var zip = Lib.zip;
it("returns an array of 'tuples'", function() {
var zip = Lib.zip;
var a = [1,2,3], b = [100, 200, 300];
assert.deepEqual(zip(a, b), [[1, 100], [2, 200], [3, 300]]);
});
it("returns a list as long as the shorter of the lists input", function() {
var a = [1,2,3], b = [100, 200, 300, 400], c = [10, 20];
assert.deepEqual(zip(a, b), [[1, 100], [2, 200], [3, 300]]);
assert.deepEqual(zip(a, c), [[1, 10], [2, 20]]);
});
});

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc