New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

partial.lenses

Package Overview
Dependencies
Maintainers
1
Versions
180
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

partial.lenses - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

91

lib/partial.lenses.js
"use strict";
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

@@ -17,21 +15,36 @@

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
//
var deleteKey = function deleteKey(k, o) {
if (o !== undefined && k in o) {
var r = {};
for (var p in o) {
if (p !== k) r[p] = o[p];
}return r;
} else {
return o;
}
if (o === undefined || !(k in o)) return o;
var r = {};
for (var p in o) {
if (p !== k) r[p] = o[p];
}return r;
};
var setKey = function setKey(k, v, o) {
if (o === undefined) return _defineProperty({}, k, v);
if (k in o && _ramda2.default.equals(v, o[k])) return o;
var r = _defineProperty({}, k, v);
for (var p in o) {
if (p !== k) r[p] = o[p];
}return r;
};
//
var conserve = function conserve(f) {
return function (n0, o) {
var n = f(n0, o);
return _ramda2.default.equals(n, o) ? o : n;
};
};
//
var lift = function lift(l) {

@@ -53,3 +66,3 @@ switch (typeof l === "undefined" ? "undefined" : _typeof(l)) {

return _ramda2.default.compose.apply(_ramda2.default, _toConsumableArray(ls.map(lift)));
return ls.length === 1 ? lift(ls[0]) : _ramda2.default.compose.apply(_ramda2.default, _toConsumableArray(ls.map(lift)));
};

@@ -65,5 +78,5 @@

return _ramda2.default.equals(x, inn) ? out : x;
}, function (y) {
}, conserve(function (y) {
return _ramda2.default.equals(y, out) ? inn : y;
});
}));
};

@@ -73,5 +86,5 @@

return _ramda2.default.lens(function (o) {
return o === undefined ? undefined : o[k];
return o && o[k];
}, function (v, o) {
return v === undefined ? deleteKey(k, o) : _extends({}, o, _defineProperty({}, k, v));
return v === undefined ? deleteKey(k, o) : setKey(k, v, o);
});

@@ -85,15 +98,12 @@ };

if (x === undefined) {
if (xs === undefined) {
return undefined;
} else {
var i = xs.findIndex(predicate);
if (i < 0) return xs;else return xs.slice(0, i).concat(xs.slice(i + 1));
}
if (xs === undefined) return undefined;
var i = xs.findIndex(predicate);
if (i < 0) return xs;
return xs.slice(0, i).concat(xs.slice(i + 1));
} else {
if (xs === undefined) {
return [x];
} else {
var i = xs.findIndex(predicate);
if (i < 0) return xs.concat([x]);else return xs.slice(0, i).concat([x], xs.slice(i + 1));
}
if (xs === undefined) return [x];
var i = xs.findIndex(predicate);
if (i < 0) return xs.concat([x]);
if (_ramda2.default.equals(x, xs[i])) return xs;
return xs.slice(0, i).concat([x], xs.slice(i + 1));
}

@@ -105,18 +115,13 @@ });

return _ramda2.default.lens(function (xs) {
return xs === undefined ? undefined : xs[i];
return xs && xs[i];
}, function (x, xs) {
if (x === undefined) {
if (xs === undefined) {
return undefined;
} else {
if (i < xs.length) return xs.slice(0, i).concat(xs.slice(i + 1));else return xs;
}
if (xs === undefined) return undefined;
if (i < xs.length) return xs.slice(0, i).concat(xs.slice(i + 1));
return xs;
} else {
if (xs === undefined) {
var ys = Array(i + 1);
ys[i] = x;
return ys;
} else {
if (i < xs.length) return xs.slice(0, i).concat([x], xs.slice(i + 1));else return xs.concat(Array(i - xs.length), [x]);
}
if (xs === undefined) return Array(i).concat([x]);
if (xs.length <= i) return xs.concat(Array(i - xs.length), [x]);
if (_ramda2.default.equals(x, xs[i])) return xs;
return xs.slice(0, i).concat([x], xs.slice(i + 1));
}

@@ -127,2 +132,2 @@ });

exports.default = L;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9wYXJ0aWFsLmxlbnNlcy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBSUEsSUFBTSxZQUFZLFNBQVosU0FBWSxDQUFDLENBQUQsRUFBSSxDQUFKLEVBQVU7QUFDMUIsTUFBSSxNQUFNLFNBQU4sSUFBbUIsS0FBSyxDQUFMLEVBQVE7QUFDN0IsUUFBTSxJQUFJLEVBQUosQ0FEdUI7QUFFN0IsU0FBSyxJQUFNLENBQU4sSUFBVyxDQUFoQjtBQUNFLFVBQUksTUFBTSxDQUFOLEVBQ0YsRUFBRSxDQUFGLElBQU8sRUFBRSxDQUFGLENBQVAsQ0FERjtLQURGLE9BR08sQ0FBUCxDQUw2QjtHQUEvQixNQU1PO0FBQ0wsV0FBTyxDQUFQLENBREs7R0FOUDtDQURnQjs7OztBQWNsQixJQUFNLE9BQU8sU0FBUCxJQUFPLElBQUs7QUFDaEIsaUJBQWUsNENBQWY7QUFDQSxTQUFLLFFBQUw7QUFBZSxhQUFPLEVBQUUsSUFBRixDQUFPLENBQVAsQ0FBUCxDQUFmO0FBREEsU0FFSyxRQUFMO0FBQWUsYUFBTyxFQUFFLEtBQUYsQ0FBUSxDQUFSLENBQVAsQ0FBZjtBQUZBO0FBR2UsYUFBTyxDQUFQLENBQWY7QUFIQSxHQURnQjtDQUFMOztBQVFiLElBQU0sSUFBSSxTQUFKLENBQUk7b0NBQUk7Ozs7U0FBTyxnQkFBRSxPQUFGLDJDQUFhLEdBQU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cm9wKGwpXG4gIGNhc2UgXCJudW1iZXJcIjogcmV0dXJuIEwuaW5kZXgobClcbiAgZGVmYXVsdDogICAgICAgcmV0dXJuIGxcbiAgfVxufVxuXG5jb25zdCBMID0gKC4uLmxzKSA9PiBSLmNvbXBvc2UoLi4ubHMubWFwKGxpZnQpKVxuXG5MLmxlbnMgPSBSLmxlbnNcbkwub3ZlciA9IFIub3ZlclxuTC5zZXQgID0gUi5zZXRcbkwudmlldyA9IFIudmlld1xuXG5MLnJlcGxhY2UgPSAoaW5uLCBvdXQpID0+XG4gIFIubGVucyh4ID0+IFIuZXF1YWxzKHgsIGlubikgPyBvdXQgOiB4LFxuICAgICAgICAgeSA9PiBSLmVxdWFscyh5LCBvdXQpID8gaW5uIDogeSlcblxuTC5wcm9wID0gayA9PlxuICBSLmxlbnMobyA9PiBvID09PSB1bmRlZmluZWQgPyB1bmRlZmluZWQgOiBvW2tdLFxuICAgICAgICAgKHYsIG8pID0+IHYgPT09IHVuZGVmaW5lZCA/IGRlbGV0ZUtleShrLCBvKSA6ICh7Li4ubywgW2tdOiB2fSkpXG5cbkwuZmluZCA9IHByZWRpY2F0ZSA9PlxuICBSLmxlbnMoeHMgPT4geHMgJiYgeHMuZmluZChwcmVkaWNhdGUpLFxuICAgICAgICAgKHgsIHhzKSA9PiB7XG4gICAgICAgICAgIGlmICh4ID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICBpZiAoeHMgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgcmV0dXJuIHVuZGVmaW5lZFxuICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICBjb25zdCBpID0geHMuZmluZEluZGV4KHByZWRpY2F0ZSlcbiAgICAgICAgICAgICAgIGlmIChpIDwgMClcbiAgICAgICAgICAgICAgICAgcmV0dXJuIHhzXG4gICAgICAgICAgICAgICBlbHNlXG4gICAgICAgICAgICAgICAgIHJldHVybiB4cy5zbGljZSgwLCBpKS5jb25jYXQoeHMuc2xpY2UoaSsxKSlcbiAgICAgICAgICAgICB9XG4gICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgaWYgKHhzID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgIHJldHVybiBbeF1cbiAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgY29uc3QgaSA9IHhzLmZpbmRJbmRleChwcmVkaWNhdGUpXG4gICAgICAgICAgICAgICBpZiAoaSA8IDApXG4gICAgICAgICAgICAgICAgIHJldHVybiB4cy5jb25jYXQoW3hdKVxuICAgICAgICAgICAgICAgZWxzZVxuICAgICAgICAgICAgICAgICByZXR1cm4geHMuc2xpY2UoMCwgaSkuY29uY2F0KFt4XSwgeHMuc2xpY2UoaSsxKSlcbiAgICAgICAgICAgICB9XG4gICAgICAgICAgIH1cbiAgICAgICAgIH0pXG5cbkwuaW5kZXggPSBpID0+XG4gIFIubGVucyh4cyA9PiB4cyA9PT0gdW5kZWZpbmVkID8gdW5kZWZpbmVkIDogeHNbaV0sXG4gICAgICAgICAoeCwgeHMpID0+IHtcbiAgICAgICAgICAgaWYgKHggPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgIGlmICh4cyA9PT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICByZXR1cm4gdW5kZWZpbmVkXG4gICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgIGlmIChpIDwgeHMubGVuZ3RoKVxuICAgICAgICAgICAgICAgICByZXR1cm4geHMuc2xpY2UoMCwgaSkuY29uY2F0KHhzLnNsaWNlKGkrMSkpXG4gICAgICAgICAgICAgICBlbHNlXG4gICAgICAgICAgICAgICAgIHJldHVybiB4c1xuICAgICAgICAgICAgIH1cbiAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICBpZiAoeHMgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgY29uc3QgeXMgPSBBcnJheShpKzEpXG4gICAgICAgICAgICAgICB5c1tpXSA9IHhcbiAgICAgICAgICAgICAgIHJldHVybiB5c1xuICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICBpZiAoaSA8IHhzLmxlbmd0aClcbiAgICAgICAgICAgICAgICAgcmV0dXJuIHhzLnNsaWNlKDAsIGkpLmNvbmNhdChbeF0sIHhzLnNsaWNlKGkrMSkpXG4gICAgICAgICAgICAgICBlbHNlXG4gICAgICAgICAgICAgICAgIHJldHVybiB4cy5jb25jYXQoQXJyYXkoaSAtIHhzLmxlbmd0aCksIFt4XSlcbiAgICAgICAgICAgICB9XG4gICAgICAgICAgIH1cbiAgICAgICAgIH0pXG5cbmV4cG9ydCBkZWZhdWx0IExcbiJdfQ==
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9wYXJ0aWFsLmxlbnNlcy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUlBLElBQU0sWUFBWSxTQUFaLFNBQVksQ0FBQyxDQUFELEVBQUksQ0FBSixFQUFVO0FBQzFCLE1BQUksTUFBTSxTQUFOLElBQW1CLEVBQUUsS0FBSyxDQUFMLENBQUYsRUFDckIsT0FBTyxDQUFQLENBREY7QUFFQSxNQUFNLElBQUksRUFBSixDQUhvQjtBQUkxQixPQUFLLElBQU0sQ0FBTixJQUFXLENBQWhCO0FBQ0UsUUFBSSxNQUFNLENBQU4sRUFDRixFQUFFLENBQUYsSUFBTyxFQUFFLENBQUYsQ0FBUCxDQURGO0dBREYsT0FHTyxDQUFQLENBUDBCO0NBQVY7O0FBVWxCLElBQU0sU0FBUyxTQUFULE1BQVMsQ0FBQyxDQUFELEVBQUksQ0FBSixFQUFPLENBQVAsRUFBYTtBQUMxQixNQUFJLE1BQU0sU0FBTixFQUNGLDJCQUFTLEdBQUksRUFBYixDQURGO0FBRUEsTUFBSSxLQUFLLENBQUwsSUF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0pKVxuICAgICAgcmV0dXJuIHhzXG4gICAgcmV0dXJuIHhzLnNsaWNlKDAsIGkpLmNvbmNhdChbeF0sIHhzLnNsaWNlKGkrMSkpXG4gIH1cbn0pXG5cbmV4cG9ydCBkZWZhdWx0IExcbiJdfQ==
{
"name": "partial.lenses",
"version": "0.1.0",
"version": "0.1.1",
"description": "Ramda compatible lenses",

@@ -5,0 +5,0 @@ "main": "lib/partial.lenses.js",

@@ -6,15 +6,32 @@ import R from "ramda"

const deleteKey = (k, o) => {
if (o !== undefined && k in o) {
const r = {}
for (const p in o)
if (p !== k)
r[p] = o[p]
return r
} else {
if (o === undefined || !(k in o))
return o
}
const r = {}
for (const p in o)
if (p !== k)
r[p] = o[p]
return r
}
const setKey = (k, v, o) => {
if (o === undefined)
return {[k]: v}
if (k in o && R.equals(v, o[k]))
return o
const r = {[k]: v}
for (const p in o)
if (p !== k)
r[p] = o[p]
return r
}
//
const conserve = f => (n0, o) => {
const n = f(n0, o)
return R.equals(n, o) ? o : n
}
//
const lift = l => {

@@ -28,3 +45,3 @@ switch (typeof l) {

const L = (...ls) => R.compose(...ls.map(lift))
const L = (...ls) => ls.length === 1 ? lift(ls[0]) : R.compose(...ls.map(lift))

@@ -38,60 +55,46 @@ L.lens = R.lens

R.lens(x => R.equals(x, inn) ? out : x,
y => R.equals(y, out) ? inn : y)
conserve(y => R.equals(y, out) ? inn : y))
L.prop = k =>
R.lens(o => o === undefined ? undefined : o[k],
(v, o) => v === undefined ? deleteKey(k, o) : ({...o, [k]: v}))
R.lens(o => o && o[k],
(v, o) => v === undefined ? deleteKey(k, o) : setKey(k, v, o))
L.find = predicate =>
R.lens(xs => xs && xs.find(predicate),
(x, xs) => {
if (x === undefined) {
if (xs === undefined) {
return undefined
} else {
const i = xs.findIndex(predicate)
if (i < 0)
return xs
else
return xs.slice(0, i).concat(xs.slice(i+1))
}
} else {
if (xs === undefined) {
return [x]
} else {
const i = xs.findIndex(predicate)
if (i < 0)
return xs.concat([x])
else
return xs.slice(0, i).concat([x], xs.slice(i+1))
}
}
})
L.find = predicate => R.lens(xs => xs && xs.find(predicate), (x, xs) => {
if (x === undefined) {
if (xs === undefined)
return undefined
const i = xs.findIndex(predicate)
if (i < 0)
return xs
return xs.slice(0, i).concat(xs.slice(i+1))
} else {
if (xs === undefined)
return [x]
const i = xs.findIndex(predicate)
if (i < 0)
return xs.concat([x])
if (R.equals(x, xs[i]))
return xs
return xs.slice(0, i).concat([x], xs.slice(i+1))
}
})
L.index = i =>
R.lens(xs => xs === undefined ? undefined : xs[i],
(x, xs) => {
if (x === undefined) {
if (xs === undefined) {
return undefined
} else {
if (i < xs.length)
return xs.slice(0, i).concat(xs.slice(i+1))
else
return xs
}
} else {
if (xs === undefined) {
const ys = Array(i+1)
ys[i] = x
return ys
} else {
if (i < xs.length)
return xs.slice(0, i).concat([x], xs.slice(i+1))
else
return xs.concat(Array(i - xs.length), [x])
}
}
})
L.index = i => R.lens(xs => xs && xs[i], (x, xs) => {
if (x === undefined) {
if (xs === undefined)
return undefined
if (i < xs.length)
return xs.slice(0, i).concat(xs.slice(i+1))
return xs
} else {
if (xs === undefined)
return Array(i).concat([x])
if (xs.length <= i)
return xs.concat(Array(i - xs.length), [x])
if (R.equals(x, xs[i]))
return xs
return xs.slice(0, i).concat([x], xs.slice(i+1))
}
})
export default L

@@ -15,22 +15,70 @@ import R from "ramda"

const testEq = (expr, lambda, expected) => it(
`${expr} equals ${show(expected)}`, () => {
const actual = lambda()
if (!R.equals(actual, expected))
throw new Error(`Expected: ${show(expected)}, actual: ${show(actual)}`)
})
const testEq = (expr, fn, expect) => it(`${expr} => ${show(expect)}`, () => {
const actual = fn()
if (!R.equals(actual, expect))
throw new Error(`Expected: ${show(expect)}, actual: ${show(actual)}`)
})
describe('L.find', () => {
testEq('L.set(L.find(R.equals(2)), undefined, [1, 2, 3])', () =>
L.set(L.find(R.equals(2)), undefined, [1, 2, 3]), [1, 3])
testEq('L.set(L.find(R.equals(2)), 4, [1, 2, 3])', () =>
L.set(L.find(R.equals(2)), 4, [1, 2, 3]), [1, 4, 3])
testEq('L.set(L.find(R.equals(2)), 2, [1, 4, 3])', () =>
L.set(L.find(R.equals(2)), 2, [1, 4, 3]), [1, 4, 3, 2])
testEq('L.set(L.find(R.equals(2)), 2, undefined)', () =>
L.set(L.find(R.equals(2)), 2, undefined), [2])
testEq('L.set(L.find(R.equals(2)), 2, [])', () =>
L.set(L.find(R.equals(2)), 2, []), [2])
testEq('L.view(L.find(R.equals(2)), undefined)', () =>
L.view(L.find(R.equals(2)), undefined), undefined)
testEq('L.view(L.find(R.equals(2)), [3])', () =>
L.view(L.find(R.equals(2)), [3]), undefined)
})
describe('L.index', () => {
testEq('L.set(L(1), 4, [1, 2, 3])', () =>
L.set(L(1), 4, [1, 2, 3]), [1, 4, 3])
testEq('L.set(L(2), 4, undefined)', () =>
L.set(L(2), 4, undefined), [,, 4])
testEq('L.set(L(2), 4, [1])', () =>
L.set(L(2), 4, [1]), [1,, 4])
testEq('L.set(L(0), undefined, [1, 2, 3])', () =>
L.set(L(0), undefined, [1, 2, 3]), [2, 3])
testEq('L.set(L(1), undefined, [1, 2, 3])', () =>
L.set(L(1), undefined, [1, 2, 3]), [1, 3])
testEq('L.set(L(2), undefined, [1, 2, 3])', () =>
L.set(L(2), undefined, [1, 2, 3]), [1, 2])
testEq('L.set(L(5), undefined, [1, 2, 3])', () =>
L.set(L(5), undefined, [1, 2, 3]), [1, 2, 3])
testEq('L.view(L(5), undefined)', () =>
L.view(L(5), undefined), undefined)
testEq('L.view(L(5), [1, 2, 3])', () =>
L.view(L(5), [1, 2, 3]), undefined)
})
describe('L.prop', () => {
testEq('L.set(L("y"), undefined, {x: 1, y: 2})', () =>
L.set(L("y"), undefined, {x: 1, y: 2}), {x: 1})
testEq('L.set(L("y"), 3, {x: 1, y: 2})', () =>
L.set(L("y"), 3, {x: 1, y: 2}), {x: 1, y: 3})
testEq('L.set(L("z"), 3, {x: 1, y: 2})', () =>
L.set(L("z"), 3, {x: 1, y: 2}), {x: 1, y: 2, z: 3})
testEq('L.set(L("z"), 3, undefined)', () =>
L.set(L("z"), 3, undefined), {z: 3})
testEq('L.view(L("z"), undefined)', () =>
L.view(L("z"), undefined), undefined)
testEq('L.view(L("z"), {x: 1})', () =>
L.view(L("z"), {x: 1}), undefined)
})
describe("L.replace", () => {
testEq('L.view(L.replace(undefined, ""), undefined)', () =>
L.view(L.replace(undefined, ""), undefined),
"")
L.view(L.replace(undefined, ""), undefined), "")
testEq('L.view(L.replace(undefined, ""), "defined")', () =>
L.view(L.replace(undefined, ""), "defined"),
"defined")
L.view(L.replace(undefined, ""), "defined"), "defined")
testEq('L.set(L.replace(undefined, ""), "", "anything")', () =>
L.set(L.replace(undefined, ""), "", "anything"),
undefined)
L.set(L.replace(undefined, ""), "", "anything"), undefined)
testEq('L.set(L.replace(undefined, ""), "defined", "anything")', () =>
L.set(L.replace(undefined, ""), "defined", "anything"),
"defined")
L.set(L.replace(undefined, ""), "defined", "anything"), "defined")
})

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