@-0/utils
Advanced tools
Comparing version 0.2.79 to 0.2.80
export { msTaskPromiseDelay } from "./taskDelay"; | ||
export { diff_keys } from "./diff_keys"; | ||
export { stringify_type } from "./stringify_type"; | ||
export { trace$ } from "./trace$"; | ||
export { unparse, parse } from "./URL"; | ||
export { obj2URL, URL2obj } from "./URL"; | ||
export { key_index_err, xKeyError } from "./xKey"; | ||
export { stringify_fn } from "./stringify_fn"; |
export { msTaskPromiseDelay } from "./taskDelay"; | ||
export { diff_keys } from "./diff_keys"; | ||
export { stringify_type } from "./stringify_type"; | ||
export { trace$ } from "./trace$"; | ||
export { unparse, parse } from "./URL"; | ||
export { obj2URL, URL2obj } from "./URL"; | ||
export { key_index_err, xKeyError } from "./xKey"; | ||
export { stringify_fn } from "./stringify_fn"; |
export const stringify_fn = (x, indent) => JSON.stringify(x, (key, value) => { | ||
if (typeof value === 'function') { | ||
return value.toString() | ||
.replace(/\r?\n|\r/g, '') | ||
.replace(/\s\s+/g, ' ') | ||
.slice(0, 12) + '...'; | ||
if (typeof value === "function") { | ||
let r = value | ||
.toString() | ||
.replace(/\r?\n|\r/g, "") | ||
.replace(/\s\s+/g, " ") | ||
.slice(0, 20) + "..."; | ||
return r.replace(/\\"/g, '"'); | ||
} | ||
@@ -8,0 +10,0 @@ else { |
import { URL_FULL, URL_SUBD, URL_DOMN, URL_QERY, URL_HASH, URL_PATH } from "@-0/keys"; | ||
export declare const parse: (URL_full: string, prefixRGX?: any) => { | ||
export declare const URL2obj: (URL_full: string, prefixRGX?: any) => { | ||
URL: string; | ||
@@ -10,3 +10,3 @@ URL_subdomain: any[]; | ||
}; | ||
export declare const unparse: (parsed?: { | ||
export declare const obj2URL: (parsed?: { | ||
URL: string; | ||
@@ -13,0 +13,0 @@ URL_subdomain: any[]; |
import qs from "querystring"; | ||
import { URL_FULL, URL_SUBD, URL_DOMN, URL_QERY, URL_HASH, URL_PATH } from "@-0/keys"; | ||
export const parse = (URL_full, prefixRGX) => { | ||
export const URL2obj = (URL_full, prefixRGX) => { | ||
let URL_subdomain = []; | ||
@@ -12,3 +12,3 @@ let URL_domain = []; | ||
const path_str = parts[0]; | ||
const full_path = path_str.split("/").filter((x) => x !== ""); | ||
const full_path = path_str.split("/").filter(x => x !== ""); | ||
if (/http/i.test(URL_full)) { | ||
@@ -22,4 +22,4 @@ URL_domain = full_path[1].split(".").slice(-2); | ||
} | ||
const query_str = parts.filter((part) => part.slice(0, 1) === "?")[0] || ""; | ||
const hash_str = parts.filter((part) => part.slice(0, 1) === "#")[0] || ""; | ||
const query_str = parts.filter(part => part.slice(0, 1) === "?")[0] || ""; | ||
const hash_str = parts.filter(part => part.slice(0, 1) === "#")[0] || ""; | ||
const URL_query = JSON.parse(JSON.stringify(qs.decode(query_str.slice(1)))); | ||
@@ -33,7 +33,7 @@ const URL_hash = hash_str.slice(1); | ||
[URL_QERY]: URL_query, | ||
[URL_HASH]: URL_hash, | ||
[URL_HASH]: URL_hash | ||
}; | ||
}; | ||
export const unparse = (parsed = parse(window.location.href), isAbsolute = false) => { | ||
const { [URL_FULL]: URL, [URL_SUBD]: URL_subdomain, [URL_DOMN]: URL_domain, [URL_PATH]: URL_path, [URL_QERY]: URL_query, [URL_HASH]: URL_hash, } = parsed; | ||
export const obj2URL = (parsed = URL2obj(window.location.href), isAbsolute = false) => { | ||
const { [URL_FULL]: URL, [URL_SUBD]: URL_subdomain, [URL_DOMN]: URL_domain, [URL_PATH]: URL_path, [URL_QERY]: URL_query, [URL_HASH]: URL_hash } = parsed; | ||
const [protocol, rest] = parsed[URL_FULL].split("//"); | ||
@@ -50,4 +50,6 @@ const [root] = rest.split("/"); | ||
const query_string = qs.encode(URL_query); | ||
const rootRelative = `${URL_path.length > 0 ? "/" + URL_path.join("/") : ""}${query_string ? "?" + query_string : ""}${URL_hash ? "#" + URL_hash : ""}`; | ||
const rootRelative = `${URL_path.length > 0 ? "/" + URL_path.join("/") : ""}${query_string | ||
? "?" + query_string | ||
: ""}${URL_hash ? "#" + URL_hash : ""}`; | ||
return !isAbsolute ? rootRelative : `${protocol}//${domain.join(".")}${rootRelative}`; | ||
}; |
@@ -0,1 +1,2 @@ | ||
import { CMD_SUB$, CMD_ARGS, CMD_ERRO, CMD_RESO, CMD_SRC$, CMD_WORK } from "@-0/keys"; | ||
import { stringify_fn } from "./stringify_fn"; | ||
@@ -29,34 +30,28 @@ export const key_index_err = (c, i) => { | ||
'sub$' | ||
'${CMD_SUB$}' | ||
- optional | ||
- topic key for for registering & targeting Commands | ||
- signatures: | ||
- "X" : String: Topic key | ||
- XX$ : Stream: for dispatching args to custom stream | ||
'args' | ||
'${CMD_ARGS}' | ||
- required | ||
- payload or accumulator reshaping payload function (Promises OK) | ||
- signatures: | ||
- PRI : primitive: static payload -> is NOT accumulated | ||
- {?} : object: static payload -> is accumulated | ||
- (+) => : function (non-nullary): dispatch payload from | ||
values accumulated from prior Command payloads | ||
- (0) => : thunk (nullary): dispatch to custom stream | ||
- {P} : Promise or (#) => {P} Promise returning function | ||
- allowed values: | ||
- true/1/"a" : Primitive: static payload is _not_ accumulated | ||
- {...} : Object: static payload _is_ accumulated | ||
- (1) => : Unary function (non-nullary): accepts accumulator | ||
- (0) => : Nullary function: dispatch to custom stream (advanced) | ||
- { P } : Promise or (#) => { P } Promise returning function | ||
'reso' | ||
'${CMD_RESO}' | ||
- required for Promise handling | ||
- converts resolved Promise payloads to Command args | ||
- signature: | ||
- ({A: accumulator}, {P: resolved Promise}) => | ||
- signature: ({ accumulator }, { resolved value }) => | ||
'erro' | ||
'${CMD_ERRO}' | ||
- recommended for Promise rejections | ||
- handles rejected Promise payloads | ||
- signature: | ||
- ({A: accumulator}, {E: error object}) => | ||
- signature: ({ accumulator }, { error object }) => | ||
${index ? `` | ||
: ` | ||
'handler' | ||
'${CMD_WORK}' | ||
- required | ||
@@ -67,3 +62,3 @@ - function that is called on payload's arrival | ||
'source$' | ||
'${CMD_SRC$}' | ||
- advanced/optional | ||
@@ -70,0 +65,0 @@ - source stream (see http://thi.ng/rstream)`} |
120
package.json
{ | ||
"name": "@-0/utils", | ||
"author": "Logan Powell", | ||
"license": "MIT", | ||
"version": "0.2.79", | ||
"description": "utilities for the `-0` org/framework built on @thi.ng/umbrella ecosystem", | ||
"main": "./lib/index.js", | ||
"type": "module", | ||
"types": "./lib/index.d.ts", | ||
"repository": "https://github.com/subs0/utils", | ||
"homepage": "https://github.com/subs0/utils", | ||
"scripts": { | ||
"madge": "madge --circular lib/", | ||
"typewatch": "tsc --project tsconfig.json", | ||
"types": "tsc --project tsconfig.build.json", | ||
"tests": "npm run madge && concurrently \"npm run typewatch\" \"jest --watchAll\"", | ||
"patch": "npm version patch && npm publish", | ||
"postgit": "git push origin master && npm run patch", | ||
"ncu": "ncu -u && npm i && npm audit fix", | ||
"git": "npm run ncu && git add . && git commit -m" | ||
}, | ||
"keywords": [ | ||
"thi.ng", | ||
"-0", | ||
"FRP", | ||
"keys", | ||
"constants" | ||
], | ||
"dependencies": { | ||
"querystring": "^0.2.0" | ||
}, | ||
"peerDependencies": { | ||
"@-0/keys": "^0.2.82", | ||
"@thi.ng/checks": "^2.8.0", | ||
"@thi.ng/rstream": "^5.1.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "^7.12.1", | ||
"@-0/keys": "^0.2.82", | ||
"@thi.ng/checks": "^2.8.0", | ||
"@thi.ng/rstream": "^5.1.0", | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.22", | ||
"@typescript-eslint/eslint-plugin": "^4.14.1", | ||
"@typescript-eslint/parser": "^4.14.1", | ||
"babel-jest": "^26.6.3", | ||
"eslint": "^7.18.0", | ||
"jest": "^26.6.3", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.5.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"prettier": { | ||
"singleQuote": false, | ||
"printWidth": 100, | ||
"endOfLine": "lf", | ||
"tabWidth": 2, | ||
"semi": false | ||
} | ||
"name": "@-0/utils", | ||
"author": "Logan Powell", | ||
"license": "MIT", | ||
"version": "0.2.80", | ||
"description": "utilities for the `-0` org/framework built on @thi.ng/umbrella ecosystem", | ||
"main": "./lib/index.js", | ||
"type": "module", | ||
"types": "./lib/index.d.ts", | ||
"repository": "https://github.com/subs0/utils", | ||
"homepage": "https://github.com/subs0/utils", | ||
"scripts": { | ||
"madge": "madge --circular lib/", | ||
"typewatch": "tsc --project tsconfig.json", | ||
"types": "tsc --project tsconfig.build.json", | ||
"test": "npm run madge && concurrently \"npm run typewatch\" \"jest --watchAll\"", | ||
"patch": "npm version patch && npm publish", | ||
"postgit": "git push origin master && npm run patch", | ||
"ncu": "ncu -u && npm i && npm audit fix", | ||
"git": "npm run ncu && git add . && git commit -m" | ||
}, | ||
"keywords": [ | ||
"thi.ng", | ||
"-0", | ||
"FRP", | ||
"keys", | ||
"constants" | ||
], | ||
"dependencies": { | ||
"querystring": "^0.2.0" | ||
}, | ||
"peerDependencies": { | ||
"@-0/keys": "^0.2.83", | ||
"@thi.ng/checks": "^2.8.0", | ||
"@thi.ng/rstream": "^5.1.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "^7.12.1", | ||
"@-0/keys": "^0.2.83", | ||
"@thi.ng/checks": "^2.8.0", | ||
"@thi.ng/rstream": "^5.1.0", | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.22", | ||
"@typescript-eslint/eslint-plugin": "^4.14.1", | ||
"@typescript-eslint/parser": "^4.14.1", | ||
"babel-jest": "^26.6.3", | ||
"eslint": "^7.18.0", | ||
"jest": "^26.6.3", | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.5.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"prettier": { | ||
"singleQuote": false, | ||
"printWidth": 100, | ||
"endOfLine": "lf", | ||
"tabWidth": 2, | ||
"semi": false | ||
} | ||
} |
@@ -1,10 +0,21 @@ | ||
import { stringify_type } from '../lib/stringify_type' | ||
import { stringify_type } from "../lib/stringify_type" | ||
const nullary2prim = () => 1 | ||
const unary2prim = x => x + 1 | ||
const binary2prim = (x, y) => x + y | ||
const nAry2prim = (x, y, z) => x + y + z | ||
const promise2prim = new Promise.resolve(1) | ||
const obj = { x: 1 } | ||
test('stringify_type: nullary', () => expect(stringify_type(nullary2prim) === 'NULLARY')) | ||
// prettier-ignore | ||
describe("stringify_type handles", () => { | ||
test("NULLARY fns", () => | ||
expect(stringify_type(() => 1)).toBe("NULLARY")) | ||
test("UNARY fns", () => | ||
expect(stringify_type(x => x + 1)).toBe("UNARY")) | ||
test("destructured UNARY fns", () => | ||
expect(stringify_type(({ x, y }) => x + y + 1)).toBe("UNARY")) | ||
test("BINARY fns", () => | ||
expect(stringify_type((x, y) => x + y)).toBe("BINARY")) | ||
test("N-ARY fns with > 2 args", () => | ||
expect(stringify_type((x, y, z) => x + y + z)).toBe("N-ARY")) | ||
test("PROMISEs", () => | ||
expect(stringify_type(new Promise((r, e) => r(1)))).toBe("PROMISE")) | ||
test("OBJECTs", () => | ||
expect(stringify_type({ x: 1 })).toBe("OBJECT")) | ||
test("& type_str NOT FOUND for primitives", () => | ||
expect(stringify_type(true)).toBe("type_str NOT FOUND")) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14832
23
309