Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/paths

Package Overview
Dependencies
Maintainers
1
Versions
199
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/paths - npm Package Compare versions

Comparing version 1.6.6 to 2.0.0

lib/index.js

22

CHANGELOG.md

@@ -6,2 +6,24 @@ # Change Log

# [2.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/paths@1.6.6...@thi.ng/paths@2.0.0) (2019-01-21)
### Build System
* update package build scripts & outputs, imports in ~50 packages ([b54b703](https://github.com/thi-ng/umbrella/commit/b54b703))
### BREAKING CHANGES
* enabled multi-outputs (ES6 modules, CJS, UMD)
- build scripts now first build ES6 modules in package root, then call
`scripts/bundle-module` to build minified CJS & UMD bundles in `/lib`
- all imports MUST be updated to only refer to package level
(not individual files anymore). tree shaking in user land will get rid of
all unused imported symbols.
## [1.6.6](https://github.com/thi-ng/umbrella/compare/@thi.ng/paths@1.6.5...@thi.ng/paths@1.6.6) (2018-12-15)

@@ -8,0 +30,0 @@

24

index.d.ts

@@ -19,3 +19,3 @@ export declare type Path = PropertyKey | PropertyKey[];

*/
export declare function toPath(path: Path): (string | number | symbol)[];
export declare const toPath: (path: Path) => (string | number | symbol)[];
/**

@@ -61,3 +61,3 @@ * Takes an arbitrary object and lookup path. Descends into object along

*/
export declare function getter(path: Path): (s: any) => any;
export declare const getter: (path: Path) => (s: any) => any;
/**

@@ -116,3 +116,3 @@ * Composes a setter function for given nested update path. Optimized

*/
export declare function setter(path: Path): (s: any, v: any) => any;
export declare const setter: (path: Path) => (s: any, v: any) => any;
/**

@@ -129,3 +129,3 @@ * Immediate use getter, i.e. same as: `getter(path)(state)`.

*/
export declare function getIn(state: any, path: Path): any;
export declare const getIn: (state: any, path: Path) => any;
/**

@@ -142,3 +142,3 @@ * Immediate use setter, i.e. same as: `setter(path)(state, val)`.

*/
export declare function setIn(state: any, path: Path, val: any): any;
export declare const setIn: (state: any, path: Path, val: any) => any;
/**

@@ -158,3 +158,3 @@ * Like `setIn()`, but takes any number of path-value pairs and applies

*/
export declare function setInMany(state: any, ...pairs: any[]): any;
export declare const setInMany: (state: any, ...pairs: any[]) => any;
/**

@@ -178,3 +178,3 @@ * Similar to `setter()`, returns a function to update values at given

*/
export declare function updater(path: Path, fn: UpdateFn<any>): (state: any, ...args: any[]) => any;
export declare const updater: (path: Path, fn: UpdateFn<any>) => (state: any, ...args: any[]) => any;
/**

@@ -195,3 +195,3 @@ * Similar to `setIn()`, but applies given function to current path

*/
export declare function updateIn(state: any, path: Path, fn: UpdateFn<any>, ...args: any[]): any;
export declare const updateIn: (state: any, path: Path, fn: UpdateFn<any>, ...args: any[]) => any;
/**

@@ -211,3 +211,3 @@ * Uses `updateIn()` and returns updated state with key for given path

*/
export declare function deleteIn(state: any, path: Path): any;
export declare const deleteIn: (state: any, path: Path) => any;
/**

@@ -224,3 +224,3 @@ * Higher-order function, similar to `setter()`. Returns function which

*/
export declare function mutator(path: Path): (_: any, x: any) => any;
export declare const mutator: (path: Path) => (_: any, x: any) => any;
/**

@@ -242,3 +242,3 @@ * Immediate use mutator, i.e. same as: `mutator(path)(state, val)`.

*/
export declare function mutIn(state: any, path: Path, val: any): any;
export declare const mutIn: (state: any, path: Path, val: any) => any;
/**

@@ -257,2 +257,2 @@ * Like `mutIn()`, but takes any number of path-value pairs and applies

*/
export declare function mutInMany(state: any, ...pairs: any[]): any;
export declare const mutInMany: (state: any, ...pairs: any[]) => any;

@@ -1,8 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const is_array_1 = require("@thi.ng/checks/is-array");
const is_string_1 = require("@thi.ng/checks/is-string");
const illegal_arguments_1 = require("@thi.ng/errors/illegal-arguments");
const _copy = (s) => Array.isArray(s) ? s.slice() : Object.assign({}, s);
const compS = (k, f) => (s, v) => { s = _copy(s); s[k] = f ? f(s[k], v) : v; return s; };
import { isString } from "@thi.ng/checks";
import { illegalArgs } from "@thi.ng/errors";
const isa = Array.isArray;
const iss = isString;
const _copy = (s) => isa(s) ? s.slice() : Object.assign({}, s);
const compS = (k, f) => (s, v) => (s = _copy(s), s[k] = (f ? f(s[k], v) : v), s);
const compG = (k, f) => (s) => s ? f(s[k]) : undefined;

@@ -25,6 +24,11 @@ /**

*/
function toPath(path) {
return is_array_1.isArray(path) ? path : is_string_1.isString(path) ? path.length > 0 ? path.split(".") : [] : path != null ? [path] : [];
}
exports.toPath = toPath;
export const toPath = (path) => isa(path) ?
path :
iss(path) ?
path.length > 0 ?
path.split(".") :
[] :
path != null ?
[path] :
[];
/**

@@ -39,3 +43,3 @@ * Takes an arbitrary object and lookup path. Descends into object along

*/
exports.exists = (obj, path) => {
export const exists = (obj, path) => {
if (obj == null) {

@@ -87,3 +91,3 @@ return false;

*/
function getter(path) {
export const getter = (path) => {
const ks = toPath(path);

@@ -105,3 +109,3 @@ let [a, b, c, d] = ks;

let f = (s) => s ? s[kl] : undefined;
for (let i = ks.length - 2; i >= 0; i--) {
for (let i = ks.length - 1; --i >= 0;) {
f = compG(ks[i], f);

@@ -111,4 +115,3 @@ }

}
}
exports.getter = getter;
};
/**

@@ -167,3 +170,3 @@ * Composes a setter function for given nested update path. Optimized

*/
function setter(path) {
export const setter = (path) => {
const ks = toPath(path);

@@ -184,3 +187,3 @@ let [a, b, c, d] = ks;

let f;
for (let i = ks.length - 1; i >= 0; i--) {
for (let i = ks.length; --i >= 0;) {
f = compS(ks[i], f);

@@ -190,4 +193,3 @@ }

}
}
exports.setter = setter;
};
/**

@@ -204,6 +206,3 @@ * Immediate use getter, i.e. same as: `getter(path)(state)`.

*/
function getIn(state, path) {
return getter(path)(state);
}
exports.getIn = getIn;
export const getIn = (state, path) => getter(path)(state);
/**

@@ -220,6 +219,3 @@ * Immediate use setter, i.e. same as: `setter(path)(state, val)`.

*/
function setIn(state, path, val) {
return setter(path)(state, val);
}
exports.setIn = setIn;
export const setIn = (state, path, val) => setter(path)(state, val);
/**

@@ -239,7 +235,5 @@ * Like `setIn()`, but takes any number of path-value pairs and applies

*/
function setInMany(state, ...pairs) {
export const setInMany = (state, ...pairs) => {
const n = pairs.length;
if ((n & 1)) {
illegal_arguments_1.illegalArgs(`require an even number of args (got ${pairs.length})`);
}
(n & 1) && illegalArgs(`require even number of args (got ${pairs.length})`);
for (let i = 0; i < n; i += 2) {

@@ -249,4 +243,3 @@ state = setIn(state, pairs[i], pairs[i + 1]);

return state;
}
exports.setInMany = setInMany;
};
/**

@@ -270,9 +263,7 @@ * Similar to `setter()`, returns a function to update values at given

*/
function updater(path, fn) {
export const updater = (path, fn) => {
const g = getter(path);
const s = setter(path);
return (state, ...args) => s(state, fn.apply(null, (args.unshift(g(state)), args)));
}
exports.updater = updater;
;
};
/**

@@ -293,6 +284,3 @@ * Similar to `setIn()`, but applies given function to current path

*/
function updateIn(state, path, fn, ...args) {
return setter(path)(state, fn.apply(null, (args.unshift(getter(path)(state)), args)));
}
exports.updateIn = updateIn;
export const updateIn = (state, path, fn, ...args) => setter(path)(state, fn.apply(null, (args.unshift(getter(path)(state)), args)));
/**

@@ -312,10 +300,9 @@ * Uses `updateIn()` and returns updated state with key for given path

*/
function deleteIn(state, path) {
export const deleteIn = (state, path) => {
const ks = [...toPath(path)];
if (ks.length > 0) {
const k = ks.pop();
return updateIn(state, ks, (x) => { x = Object.assign({}, x); delete x[k]; return x; });
return updateIn(state, ks, (x) => (x = Object.assign({}, x), delete x[k], x));
}
}
exports.deleteIn = deleteIn;
};
/**

@@ -332,3 +319,3 @@ * Higher-order function, similar to `setter()`. Returns function which

*/
function mutator(path) {
export const mutator = (path) => {
const ks = toPath(path);

@@ -359,4 +346,3 @@ let [a, b, c, d] = ks;

}
}
exports.mutator = mutator;
};
/**

@@ -378,6 +364,3 @@ * Immediate use mutator, i.e. same as: `mutator(path)(state, val)`.

*/
function mutIn(state, path, val) {
return mutator(path)(state, val);
}
exports.mutIn = mutIn;
export const mutIn = (state, path, val) => mutator(path)(state, val);
/**

@@ -396,7 +379,5 @@ * Like `mutIn()`, but takes any number of path-value pairs and applies

*/
function mutInMany(state, ...pairs) {
export const mutInMany = (state, ...pairs) => {
const n = pairs.length;
if ((n & 1)) {
illegal_arguments_1.illegalArgs(`require an even number of args (got ${pairs.length})`);
}
(n & 1) && illegalArgs(`require even number of args (got ${pairs.length})`);
for (let i = 0; i < n && state; i += 2) {

@@ -406,3 +387,2 @@ state = mutIn(state, pairs[i], pairs[i + 1]);

return state;
}
exports.mutInMany = mutInMany;
};
{
"name": "@thi.ng/paths",
"version": "1.6.6",
"version": "2.0.0",
"description": "immutable, optimized path-based object property / array accessors",
"main": "./index.js",
"module": "./index.js",
"main": "./lib/index.js",
"umd:main": "./lib/index.umd.js",
"typings": "./index.d.ts",

@@ -15,8 +17,10 @@ "repository": {

"scripts": {
"build": "yarn run clean && tsc --declaration",
"clean": "rm -rf *.js *.d.ts .nyc_output build coverage doc",
"build": "yarn clean && yarn build:es6 && yarn build:bundle",
"build:es6": "tsc --declaration",
"build:bundle": "../../scripts/bundle-module paths checks errors",
"test": "rimraf build && tsc -p test/tsconfig.json && nyc mocha build/test/*.js",
"clean": "rimraf *.js *.d.ts .nyc_output build coverage doc lib",
"cover": "yarn test && nyc report --reporter=lcov",
"doc": "node_modules/.bin/typedoc --mode modules --out doc src",
"pub": "yarn run build && yarn publish --access public",
"test": "rm -rf build && tsc -p test && nyc mocha build/test/*.js"
"pub": "yarn build && yarn publish --access public"
},

@@ -28,8 +32,8 @@ "devDependencies": {

"nyc": "^13.1.0",
"typedoc": "^0.13.0",
"typedoc": "^0.14.0",
"typescript": "^3.2.2"
},
"dependencies": {
"@thi.ng/checks": "^1.5.14",
"@thi.ng/errors": "^0.1.12"
"@thi.ng/checks": "^2.0.0",
"@thi.ng/errors": "^1.0.0"
},

@@ -40,2 +44,3 @@ "keywords": [

"ES6",
"delete",
"getter",

@@ -48,3 +53,4 @@ "immutable",

"setter",
"typescript"
"typescript",
"update"
],

@@ -54,3 +60,11 @@ "publishConfig": {

},
"gitHead": "159ce8f6b1d2dad1e12f2ba3f4f7b60d1623acee"
"browserslist": [
"since 2018-07"
],
"browser": {
"process": false,
"setTimeout": false
},
"sideEffects": false,
"gitHead": "348e7303b8b4d2749a02dd43e3f78d711242e4fe"
}
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