pepka 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.cjs +1 -1
- package/dist/bundle.d.ts +84 -47
- package/dist/bundle.mjs +1 -1
- package/package.json +1 -1
- package/src/async.ts +36 -0
- package/src/common.ts +42 -6
- package/src/index.ts +1 -0
- package/src/quick.ts +6 -5
- package/src/safe.ts +36 -100
- package/src/strings.ts +2 -2
- package/src/types.ts +2 -1
package/dist/bundle.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=Symbol("Placeholder"),
|
|
1
|
+
"use strict";const e=Symbol("Placeholder"),t=t=>{let r=0;for(const s of t)s!==e&&r++;return r},r=(t,r)=>{const s=t.length,o=t.slice(),p=r.length;let n=p,x=0;for(;n&&x<s;x++)o[x]===e&&(o[x]=r[p-n],n--);for(x=s;n;x++,n--)o[x]=r[p-n];return o},s=(e,o,p)=>{const n=e.length-o.length-t(p);if(n<1)return e(...r(o,p));{const t=(...t)=>s(e,r(o,p),t);return t.$args_left=n,t}},o=e=>(...r)=>e.length>t(r)?s(e,[],r):e(...r);function p(t){return function(r,s){const o=r===e,p=arguments.length;if(1===p&&o)throw new Error("Senseless placeholder usage.");return p>1?o?(t=>function(r){return r===e?t:t(r)})((e=>t(e,s))):t(r,s):e=>t(r,e)}}function n(e){return o(e)}const x=void 0,a=1/0,c=e=>typeof e,l=e=>null===e,i=e=>"number"==c(e),u=e=>Array.isArray(e),f=e=>"function"===c(e),h=e=>!l(e)&&"object"===c(e),m={u:"U",b:"B",n:"N",s:"S",f:"F"},y=Symbol(),d=e=>{const t=c(e);return"object"===t?l(e)?"Null":e.constructor.name:m[t[0]]+t.slice(1)},g=p(((e,t)=>d(t)===e)),b=e=>e.length,q=e=>l(e)||(e=>e===x)(e),w=p(((e,t)=>e===t)),j=p(((e,t)=>{const r=d(e);if(w(r,d(t))&&(w(r,"Object")||w(r,"Array"))){if(l(e)||l(t))return w(e,t);if(w(e,t))return!0;for(const r of[e,t])for(const s in r)if(!(w(r,t)&&s in e||w(r,e)&&s in t&&j(e[s],t[s])))return!1;return!0}return w(e,t)})),O=p(((e,t)=>{if((e=>"string"===c(e))(t))return t.includes(e);for(const r of t)if(j(r,e))return!0;return!1})),A=e=>p(((t,r)=>{const s=b(t);if(s>b(r))return!1;for(let o=0;o<s;o++)if(!e(r[o],t[o]))return!1;return!0})),S=p(((e,t)=>(t.push(e),t))),E=n(((e,t,r)=>(r[e]=t,r))),k=n(((e,t,r)=>r.reduce(e,t))),z=n(((e,t,r)=>{for(let s in r)switch(d(r[s])){case"Array":if(e>1&&"Array"===d(t[s]))switch(e){case 2:const o=t[s],p=r[s];for(const t in p)o[t]?z(e,o[t],p[t]):o[t]=p[t];break;case 3:t[s].push(...r[s])}else t[s]=r[s];break;case"Object":if("Object"===d(t[s])){z(e,t[s],r[s]);break}default:t[s]=r[s]}return t})),v=z(1),P=z(2),D=z(3),W=p(((e,t)=>Object.assign(e,t))),N=p(((e,t)=>{let r,s,o,p;for(r in e)r in t&&(s=e[r],[o,p]=f(s)?s(t[r],r,t):[s,t[r]],t[q(o)?r:o]=p,r!==o&&delete t[r]);return t})),B=p(((e,t)=>{for(let r in t)t[r]=e(t[r],+r,t);return t})),T=p(((e,t)=>B(e,t))),_=p(((e,t)=>{const r=u(t);let s,o;r&&(s=0,o=[]);for(let s in t)e(t[s],s)||(r?o.push(+s):delete t[s]);if(r)for(const e of o)t.splice(e-s++,1);return t})),C=e=>{let t;for(const r in e)t=e[r],h(t)&&C(t);return Object.freeze(e)},F=e=>Object.freeze(e),I=p(((e,t)=>t.unshift(e))),U=n(((e,t,r)=>{const s=e[0];return E(s,e.length<2?t:U(e.slice(1),t,h(r[s])?r[s]:{}),r)})),$=p(((e,t)=>_(((t,r)=>!O(r,e)),t))),K=A(w),L=e=>(...t)=>t[e],X=p(((e,t)=>e==t)),G=o(((e,t,r,s)=>e(s)?t(s):r(s))),H=n(((e,t,r)=>G(e,t,fe,r))),J=(...t)=>(...r)=>{let s,o=!0;for(let p=b(t)-1;p>-1;p--)o?(o=!1,s=t[p](...r)):s=s===e?t[p]():t[p](s);return s},M=p(((e,t)=>e.bind(t))),Q=p(((e,t)=>t[e])),R=n(((e,t,r)=>r.slice(e,i(t)?t:a))),V=e=>p(((t,r)=>e(r,t))),Y=Q(0),Z=R(1,a),ee=p(((e,t)=>e+t)),te=p(((e,t)=>t-e)),re=p(((e,t)=>e*t)),se=p(((e,t)=>e<t)),oe=p(((e,t)=>e>t)),pe=p(((e,t)=>e<=t)),ne=p(((e,t)=>e>=t)),xe=p(((e,t)=>t.sort(e))),ae=p(((e,t)=>t.find(e))),ce=p(((e,t)=>t.findIndex(e))),le=p(((e,t)=>ce(j(e),t))),ie=p(((e,t)=>e/t)),ue=e=>()=>e,fe=e=>e,he=A(((e,t)=>j(e,t))),me=e=>!e,ye=p(((e,t)=>e.test(t))),de=p(((e,t)=>(e(t),t))),ge=p(((e,t)=>[...t,e])),be=p(((e,t)=>[...t,e])),qe=p(((e,t)=>t.flat(e))),we=p(((e,t)=>t.split(e))),je=ue(!0),Oe=ue(!1),Ae=p(((e,t)=>t(...e))),Se=o(((e,t,r)=>r[t](...e))),Ee=e=>(...t)=>{const r=e(...t),s=f(r);return!s||s&&r.$args_left<=0?me(r):Ee(r)},ke=p(((e,t)=>ve(ee(e),t-e))),ze=p(((e,t)=>e.filter(V(O)(t)))),ve=p(((e,t)=>[...Array(t)].map(((t,r)=>e(r))))),Pe=p(((e,t)=>{for(const[r,s]of e)if(r(t))return s(t)})),De=n(((e,t,r)=>({...r,[e]:t}))),We=n(((e,t,r)=>J((s=>De(s,b(e)<2?t:We(R(1,a,e),t,h(r[s])?r[s]:{}),r)),Y)(e))),Ne=p(((e,t)=>t.every(e))),Be=p(((e,t)=>t.some(e))),Te=p(((e,t)=>e.every((e=>e(t))))),_e=p(((e,t)=>e.some((e=>e(t))))),Ce=p(((e,t)=>t[e])),Fe=n(((e,t,r)=>j(r[e],t))),Ie=n(((e,t,r)=>j(t[e],r[e]))),Ue=n(((e,t,r)=>b(t)?q(r)?e:J((s=>s in r?Ue(e,R(1,a,t),r[s]):e),Y)(t):r)),$e=Ue(x),Ke=n(((e,t,r)=>j($e(e,r),t))),Le=n(((e,t,r)=>j($e(e,t),$e(e,r)))),Xe=J(G(j(y),Oe,je),Ue(y)),Ge=/^(.*?)(8|16|32|64)(Clamped)?Array$/,He=(e,t=!1)=>{const r=d(e);switch(r){case"Null":case"String":case"Number":case"Boolean":case"Symbol":return e;case"Array":return t?[...e]:Ze(J(He,L(0)),e);case"Object":if(t)return{...e};const s={};for(let t in e)s[t]=He(e[t]);return s;default:return Ge.test(r)?e.constructor.from(e):e}},Je=e=>He(e,!0),Me=n(((e,t,r)=>k(e,He(t),r))),Qe=p(((e,t)=>pt(e,t))),Re=p(((e,t)=>{const r={};for(const s of e)s in t&&(r[s]=t[s]);return r})),Ve=p(((e,t)=>pt(((t,r)=>!O(r,e)),t))),Ye=p(((e,t)=>t.concat(e))),Ze=p(((e,t)=>t.map(e))),et=p(((e,t)=>T(e,Je(t)))),tt=p(((e,t)=>t.join(e))),rt=p(((e,t)=>t.forEach(e))),st=n(((e,t,r)=>t(r)&&e(r))),ot=n(((e,t,r)=>r.replace(e,t))),pt=p(((e,t)=>u(t)?t.filter(e):_(e,{...t}))),nt=p(((e,t)=>Object.assign({},e,t))),xt=p(((e,t)=>v(He(e),He(t)))),at=p(((e,t)=>P(He(e),He(t)))),ct=p(((e,t)=>D(He(e),He(t)))),lt=n(((e,t,r)=>De(e,t(r[e]),r))),it=p(((e,t)=>N(e,Object.assign({},t)))),ut=p(((e,t)=>Ze(((e,r)=>[e,t[r]]),e))),ft=p(((e,t)=>Me(((e,r,s)=>De(r,t[s],e)),{},e))),ht=n(((e,t,r)=>Ze(((t,s)=>e(t,r[s])),t))),mt=fe,yt=fe,dt=fe,gt=Ee,bt=ge,qt=Be,wt=(()=>{const e=async(t,r,s)=>{s<r.length&&(await t(r[s]),await e(t,r,++s))};return p(((t,r)=>e(t,r,0)))})(),jt=p((async(e,t)=>(await e(t),t))),Ot=p(((e,t)=>Promise.all(t.map(e)))),At=(()=>{const e=async(t,r,s)=>~s?await e(t,[await t[s](...r)],--s):Y(r);return(...t)=>(...r)=>e(t,r,t.length-1)})();exports.F=Oe,exports.T=je,exports.__=e,exports.add=ee,exports.all=Ne,exports.allPass=Te,exports.always=ue,exports.any=Be,exports.anyPass=_e,exports.append=ge,exports.assoc=De,exports.assocPath=We,exports.bind=M,exports.both=st,exports.callFrom=Se,exports.callWith=Ae,exports.clone=He,exports.cloneShallow=Je,exports.complement=Ee,exports.compose=J,exports.composeAsync=At,exports.concat=Ye,exports.cond=Pe,exports.curry=o,exports.curry2=p,exports.curry3=n,exports.divide=ie,exports.echo=dt,exports.empty=e=>{switch(d(e)){case"String":return"";case"Object":return{};case"Array":return[];default:return x}},exports.eq=w,exports.equals=j,exports.explore=(e,t="log")=>de((r=>console[t](e,r))),exports.filter=pt,exports.find=ae,exports.findIndex=ce,exports.flat=e=>e.flat(a),exports.flatShallow=e=>e.flat(),exports.flatTo=qe,exports.flip=V,exports.forEach=rt,exports.forEachAsync=Ot,exports.forEachSerial=wt,exports.freeze=e=>C(He(e)),exports.freezeShallow=e=>F(He(e)),exports.fromPairs=e=>Object.fromEntries(e),exports.genBy=ve,exports.getTmpl=e=>{const t=[],r=[],s=e.length;let o,p,n,x=0,a=0,c=!1,l=Y(e),i=!1;for(x=0;x<s;x++)switch(o=e[x],o){case"{":if(!l){c=!0,a=x;break}case"}":if(!l){c=!1,t.push(""),r.push(e.slice(a+1,x));break}default:n=e[x+1],i="\\"===o,c||i&&("{"===n||"}"===n)||(p=t.length-1,p<0&&(t.push(""),p++),t[p]+=o),l=i}return e=>{const s=[],o=t.length-1;for(const p in t)x=+p,s.push(t[x]),x!==o&&s.push($e(r[x].split("."),e));return s.join("")}},exports.gt=se,exports.gte=pe,exports.head=Y,exports.identity=fe,exports.ifElse=G,exports.includes=O,exports.indexOf=le,exports.intersection=ze,exports.isEmpty=e=>{switch(d(e)){case"String":case"Array":return 0==b(e);case"Object":for(const t in e)return!1;return!0;default:return null}},exports.isNil=q,exports.join=tt,exports.keys=e=>Object.keys(e),exports.last=e=>e[b(e)-1],exports.length=b,exports.lt=oe,exports.lte=ne,exports.map=Ze,exports.mapKeys=it,exports.mapObj=et,exports.memoize=e=>{let t,r=!1;return()=>r?t:(r=!0,t=e())},exports.mergeDeep=xt,exports.mergeDeepAdd=ct,exports.mergeDeepX=at,exports.mergeShallow=nt,exports.mirror=mt,exports.multiply=re,exports.noop=()=>{},exports.not=me,exports.notf=gt,exports.nth=Q,exports.omit=Ve,exports.once=e=>{let t,r=!1;return(...s)=>r?t:(r=!0,t=e(...s))},exports.overProp=lt,exports.path=$e,exports.pathEq=Ke,exports.pathExists=Xe,exports.pathOr=Ue,exports.pathsEq=Le,exports.pick=Re,exports.pickBy=Qe,exports.prepend=be,exports.prop=Ce,exports.propEq=Fe,exports.propsEq=Ie,exports.push=bt,exports.qappend=S,exports.qassoc=E,exports.qassocPath=U,exports.qempty=e=>{if(u(e))e.splice(0);else for(const t in e)delete e[t];return e},exports.qfilter=_,exports.qfreeze=C,exports.qfreezeShallow=F,exports.qmap=B,exports.qmapKeys=N,exports.qmapObj=T,exports.qmergeDeep=v,exports.qmergeDeepAdd=D,exports.qmergeDeepX=P,exports.qmergeShallow=W,exports.qomit=$,exports.qprepend=I,exports.qreduce=k,exports.qreverse=e=>e.reverse(),exports.qstartsWith=K,exports.qstartsWithWith=A,exports.range=ke,exports.reduce=Me,exports.reflect=yt,exports.replace=ot,exports.reverse=e=>J((t=>Me(((r,s,o)=>S(e[t-o],r)),[],e)),ee(-1),b)(e),exports.sizeof=e=>{if("Object"===d(e)){let t=0;for(let r in e)t++;return t}return b(e)},exports.slice=R,exports.some=qt,exports.sort=xe,exports.split=we,exports.startsWith=he,exports.subtract=te,exports.symbol=y,exports.tail=Z,exports.take=L,exports.tap=de,exports.test=ye,exports.toLower=e=>e.toLowerCase(),exports.toPairs=e=>Object.entries(e),exports.toUpper=e=>e.toUpperCase(),exports.trim=e=>e.trim(),exports.type=d,exports.typeIs=g,exports.uncurry=e=>(...t)=>k(((e,t)=>e?e(t):e),e,t),exports.uniq=e=>k(((e,t)=>ae(j(t),e)?e:S(t,e)),[],e),exports.values=e=>Object.values(e),exports.waitAll=e=>Promise.all(e),exports.waitTap=jt,exports.weakEq=X,exports.when=H,exports.zip=ut,exports.zipObj=ft,exports.zipWith=ht;
|
package/dist/bundle.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type Reducer<T = any> = (accum: T, cur: any, index: number) => T;
|
|
|
9
9
|
export type AnyFunc<ReturnT = any, Args extends AnyArgs = AnyArgs> = (...args: Args) => ReturnT;
|
|
10
10
|
export type TupleFn<ARG1 = any, ARG2 = any, Out = any> = (a: ARG1, b: ARG2) => Out;
|
|
11
11
|
export type Curried<Args extends AnyArgs = AnyArgs, ReturnT = any> = (arg: Args[number]) => Curried<Args> | ReturnT;
|
|
12
|
+
export type BasicType = "String" | "Object" | "Number" | "Symbol" | "Array" | "Null" | "Undefined";
|
|
12
13
|
type Placeholder = symbol;
|
|
13
14
|
export declare const __: Placeholder;
|
|
14
15
|
export declare const curry: (fn: AnyFunc) => (...args: AnyArgs) => any;
|
|
@@ -25,27 +26,42 @@ export declare const uncurry: <Args extends any[] = any[], ReturnT = any>(fn: Cu
|
|
|
25
26
|
export declare const symbol: unique symbol;
|
|
26
27
|
export declare const toLower: (s: string) => string;
|
|
27
28
|
export declare const toUpper: (s: string) => string;
|
|
28
|
-
export declare const type: (s: any) =>
|
|
29
|
+
export declare const type: (s: any) => string;
|
|
29
30
|
export declare const typeIs: {
|
|
30
31
|
(a: symbol, b: any): (a: string) => boolean;
|
|
31
32
|
(a: string, b: symbol): (b: any) => boolean;
|
|
32
33
|
(a: string): (b: any) => boolean;
|
|
33
34
|
(a: string, b: any): boolean;
|
|
34
35
|
};
|
|
35
|
-
|
|
36
|
+
declare const length$1: (s: any[] | string) => number;
|
|
37
|
+
export declare const isNil: (s: any) => boolean;
|
|
36
38
|
export declare const eq: {
|
|
37
39
|
(a: symbol, b: any): (a: any) => boolean;
|
|
38
40
|
(a: any, b: symbol): (b: any) => boolean;
|
|
39
41
|
(a: any): (b: any) => boolean;
|
|
40
42
|
(a: any, b: any): boolean;
|
|
41
43
|
};
|
|
42
|
-
export declare const
|
|
44
|
+
export declare const equals: {
|
|
43
45
|
(a: symbol, b: any): (a: any) => boolean;
|
|
44
46
|
(a: any, b: symbol): (b: any) => boolean;
|
|
45
47
|
(a: any): (b: any) => boolean;
|
|
46
48
|
(a: any, b: any): boolean;
|
|
47
49
|
};
|
|
48
|
-
export declare const
|
|
50
|
+
export declare const includes: {
|
|
51
|
+
(a: symbol, b: unknown[]): (a: unknown) => boolean;
|
|
52
|
+
(a: unknown, b: symbol): (b: unknown[]) => boolean;
|
|
53
|
+
(a: unknown): (b: unknown[]) => boolean;
|
|
54
|
+
(a: unknown, b: unknown[]): boolean;
|
|
55
|
+
};
|
|
56
|
+
/** @param start string | any[] @param s string | any[] */
|
|
57
|
+
export declare const qstartsWithWith: (comparator: (x: any, y: any) => boolean) => {
|
|
58
|
+
(a: symbol, b: string | any[]): (a: string | any[]) => boolean;
|
|
59
|
+
(a: string | any[], b: symbol): (b: string | any[]) => boolean;
|
|
60
|
+
(a: string | any[]): (b: string | any[]) => boolean;
|
|
61
|
+
(a: string | any[], b: string | any[]): boolean;
|
|
62
|
+
};
|
|
63
|
+
export declare const take: (argN: number) => (...args: any[]) => any;
|
|
64
|
+
export declare const weakEq: {
|
|
49
65
|
(a: symbol, b: any): (a: any) => boolean;
|
|
50
66
|
(a: any, b: symbol): (b: any) => boolean;
|
|
51
67
|
(a: any): (b: any) => boolean;
|
|
@@ -67,12 +83,6 @@ export declare const nth: {
|
|
|
67
83
|
(a: number): (b: string | unknown[]) => unknown;
|
|
68
84
|
(a: number, b: string | unknown[]): unknown;
|
|
69
85
|
};
|
|
70
|
-
export declare const includes: {
|
|
71
|
-
(a: symbol, b: unknown[]): (a: unknown) => boolean;
|
|
72
|
-
(a: unknown, b: symbol): (b: unknown[]) => boolean;
|
|
73
|
-
(a: unknown): (b: unknown[]) => boolean;
|
|
74
|
-
(a: unknown, b: unknown[]): boolean;
|
|
75
|
-
};
|
|
76
86
|
export declare const slice: (...args: AnyArgs) => any;
|
|
77
87
|
export declare const flip: <T extends AnyFunc>(fn: T) => {
|
|
78
88
|
(a: symbol, b: Parameters<T>[0]): (a: Parameters<T>[1]) => any;
|
|
@@ -80,44 +90,53 @@ export declare const flip: <T extends AnyFunc>(fn: T) => {
|
|
|
80
90
|
(a: Parameters<T>[1]): (b: Parameters<T>[0]) => any;
|
|
81
91
|
(a: Parameters<T>[1], b: Parameters<T>[0]): any;
|
|
82
92
|
};
|
|
93
|
+
/** @returns first element of an array. */
|
|
83
94
|
export declare const head: <T = any>(xs: T[] | string) => T;
|
|
95
|
+
/** @returns last element of an array. */
|
|
84
96
|
export declare const tail: any;
|
|
97
|
+
/** @param a @param b @returns a+b */
|
|
85
98
|
export declare const add: {
|
|
86
99
|
(a: symbol, b: number): (a: number) => number;
|
|
87
100
|
(a: number, b: symbol): (b: number) => number;
|
|
88
101
|
(a: number): (b: number) => number;
|
|
89
102
|
(a: number, b: number): number;
|
|
90
103
|
};
|
|
104
|
+
/** @param a @param b @returns b-a */
|
|
91
105
|
export declare const subtract: {
|
|
92
106
|
(a: symbol, b: number): (a: number) => number;
|
|
93
107
|
(a: number, b: symbol): (b: number) => number;
|
|
94
108
|
(a: number): (b: number) => number;
|
|
95
109
|
(a: number, b: number): number;
|
|
96
110
|
};
|
|
111
|
+
/**@param a @param b @returns a*b */
|
|
97
112
|
export declare const multiply: {
|
|
98
113
|
(a: symbol, b: number): (a: number) => number;
|
|
99
114
|
(a: number, b: symbol): (b: number) => number;
|
|
100
115
|
(a: number): (b: number) => number;
|
|
101
116
|
(a: number, b: number): number;
|
|
102
117
|
};
|
|
118
|
+
/** @param a @param b @returns a<b */
|
|
103
119
|
export declare const gt: {
|
|
104
120
|
(a: symbol, b: number): (a: number) => boolean;
|
|
105
121
|
(a: number, b: symbol): (b: number) => boolean;
|
|
106
122
|
(a: number): (b: number) => boolean;
|
|
107
123
|
(a: number, b: number): boolean;
|
|
108
124
|
};
|
|
125
|
+
/** @param a @param b @returns a>b */
|
|
109
126
|
export declare const lt: {
|
|
110
127
|
(a: symbol, b: number): (a: number) => boolean;
|
|
111
128
|
(a: number, b: symbol): (b: number) => boolean;
|
|
112
129
|
(a: number): (b: number) => boolean;
|
|
113
130
|
(a: number, b: number): boolean;
|
|
114
131
|
};
|
|
132
|
+
/** @param a @param b @returns a<=b */
|
|
115
133
|
export declare const gte: {
|
|
116
134
|
(a: symbol, b: number): (a: number) => boolean;
|
|
117
135
|
(a: number, b: symbol): (b: number) => boolean;
|
|
118
136
|
(a: number): (b: number) => boolean;
|
|
119
137
|
(a: number, b: number): boolean;
|
|
120
138
|
};
|
|
139
|
+
/** @param a @param b @returns a>=b */
|
|
121
140
|
export declare const lte: {
|
|
122
141
|
(a: symbol, b: number): (a: number) => boolean;
|
|
123
142
|
(a: number, b: symbol): (b: number) => boolean;
|
|
@@ -154,12 +173,17 @@ export declare const divide: {
|
|
|
154
173
|
(a: number): (b: number) => number;
|
|
155
174
|
(a: number, b: number): number;
|
|
156
175
|
};
|
|
157
|
-
export declare const isNil: (s: any) => boolean;
|
|
158
|
-
declare const length$1: (s: any[] | string) => number;
|
|
159
176
|
export declare const always: <T = any>(s: T) => () => T;
|
|
160
177
|
export declare const identity: (s: any) => any;
|
|
161
178
|
export declare const trim: (s: string) => string;
|
|
162
179
|
export declare const last: (s: any[] | string) => any;
|
|
180
|
+
/** @param start string | any[] @param s string | any[] */
|
|
181
|
+
export declare const startsWith: {
|
|
182
|
+
(a: symbol, b: string | any[]): (a: string | any[]) => boolean;
|
|
183
|
+
(a: string | any[], b: symbol): (b: string | any[]) => boolean;
|
|
184
|
+
(a: string | any[]): (b: string | any[]) => boolean;
|
|
185
|
+
(a: string | any[], b: string | any[]): boolean;
|
|
186
|
+
};
|
|
163
187
|
type NotOverload = {
|
|
164
188
|
(x: true): false;
|
|
165
189
|
(x: false): true;
|
|
@@ -239,6 +263,7 @@ export declare const range: {
|
|
|
239
263
|
(a: number): (b: number) => any[];
|
|
240
264
|
(a: number, b: number): any[];
|
|
241
265
|
};
|
|
266
|
+
/** @param xs any[] @returns xs without duplicates. */
|
|
242
267
|
export declare const uniq: (xs: any[]) => any;
|
|
243
268
|
export declare const intersection: {
|
|
244
269
|
(a: symbol, b: any[]): (a: any[]) => any[];
|
|
@@ -304,13 +329,16 @@ export declare const anyPass: {
|
|
|
304
329
|
(a: Cond[]): (b: any) => boolean;
|
|
305
330
|
(a: Cond[], b: any): boolean;
|
|
306
331
|
};
|
|
332
|
+
/** @param key string @param o AnyObject @returns o[key] */
|
|
307
333
|
export declare const prop: {
|
|
308
334
|
(a: symbol, b: AnyObject): (a: string) => any;
|
|
309
335
|
(a: string, b: symbol): (b: AnyObject) => any;
|
|
310
336
|
(a: string): (b: AnyObject) => any;
|
|
311
337
|
(a: string, b: AnyObject): any;
|
|
312
338
|
};
|
|
339
|
+
/** @param key string @param value any @param o AnyObject @returns o[key] equals value */
|
|
313
340
|
export declare const propEq: (...args: AnyArgs) => any;
|
|
341
|
+
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
314
342
|
export declare const propsEq: (...args: AnyArgs) => any;
|
|
315
343
|
export declare const pathOr: any;
|
|
316
344
|
export declare const path: any;
|
|
@@ -357,12 +385,6 @@ export declare const concat: {
|
|
|
357
385
|
(a: string | any[]): (b: string | any[]) => string | any[];
|
|
358
386
|
(a: string | any[], b: string | any[]): string | any[];
|
|
359
387
|
};
|
|
360
|
-
export declare const join: {
|
|
361
|
-
(a: symbol, b: string[]): (a: string) => string;
|
|
362
|
-
(a: string, b: symbol): (b: string[]) => string;
|
|
363
|
-
(a: string): (b: string[]) => string;
|
|
364
|
-
(a: string, b: string[]): string;
|
|
365
|
-
};
|
|
366
388
|
export declare const map: {
|
|
367
389
|
(a: symbol, b: any[]): (a: (s: any, i?: number, list?: any[]) => any) => any[];
|
|
368
390
|
(a: (s: any, i?: number, list?: any[]) => any, b: symbol): (b: any[]) => any[];
|
|
@@ -375,6 +397,12 @@ export declare const mapObj: {
|
|
|
375
397
|
(a: (s: any, i?: string, list?: any[]) => any): (b: AnyObject) => (b: AnyObject) => (a: (s: any, i?: number | undefined, list?: any[] | undefined) => any) => any[];
|
|
376
398
|
(a: (s: any, i?: string, list?: any[]) => any, b: AnyObject): (b: AnyObject) => (a: (s: any, i?: number | undefined, list?: any[] | undefined) => any) => any[];
|
|
377
399
|
};
|
|
400
|
+
export declare const join: {
|
|
401
|
+
(a: symbol, b: string[]): (a: string) => string;
|
|
402
|
+
(a: string, b: symbol): (b: string[]) => string;
|
|
403
|
+
(a: string): (b: string[]) => string;
|
|
404
|
+
(a: string, b: string[]): string;
|
|
405
|
+
};
|
|
378
406
|
export declare const forEach: {
|
|
379
407
|
(a: symbol, b: any[]): (a: (s: any) => any) => void;
|
|
380
408
|
(a: (s: any) => any, b: symbol): (b: any[]) => void;
|
|
@@ -451,35 +479,6 @@ export declare const zipObj: {
|
|
|
451
479
|
* @param b T2[]
|
|
452
480
|
*/
|
|
453
481
|
export declare const zipWith: (...args: AnyArgs) => any;
|
|
454
|
-
/** One promise waits for another. */
|
|
455
|
-
export declare const forEachSerial: {
|
|
456
|
-
(a: symbol, b: any[]): (a: AnyFunc) => Promise<void>;
|
|
457
|
-
(a: AnyFunc, b: symbol): (b: any[]) => Promise<void>;
|
|
458
|
-
(a: AnyFunc): (b: any[]) => Promise<void>;
|
|
459
|
-
(a: AnyFunc, b: any[]): Promise<void>;
|
|
460
|
-
};
|
|
461
|
-
/** Promise.all wrapper for functional pipelining. */
|
|
462
|
-
export declare const waitAll: (promises: Promise<any>[]) => Promise<any[]>;
|
|
463
|
-
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
464
|
-
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
465
|
-
* @param {T} s - any value to tap and return back
|
|
466
|
-
* @returns {T}
|
|
467
|
-
*/
|
|
468
|
-
export declare const waitTap: {
|
|
469
|
-
(a: symbol, b: any): (a: AnyFunc) => Promise<any>;
|
|
470
|
-
(a: AnyFunc, b: symbol): (b: any) => Promise<any>;
|
|
471
|
-
(a: AnyFunc): (b: any) => Promise<any>;
|
|
472
|
-
(a: AnyFunc, b: any): Promise<any>;
|
|
473
|
-
};
|
|
474
|
-
/** Waits for all promises mapped by the fn. */
|
|
475
|
-
export declare const forEachAsync: {
|
|
476
|
-
(a: symbol, b: any[]): (a: (item: any) => Promise<any>) => Promise<any[]>;
|
|
477
|
-
(a: (item: any) => Promise<any>, b: symbol): (b: any[]) => Promise<any[]>;
|
|
478
|
-
(a: (item: any) => Promise<any>): (b: any[]) => Promise<any[]>;
|
|
479
|
-
(a: (item: any) => Promise<any>, b: any[]): Promise<any[]>;
|
|
480
|
-
};
|
|
481
|
-
/** The same as compose, but waits for promises in chains and returns a Promise. */
|
|
482
|
-
export declare const composeAsync: <T = any>(...fns: AnyFunc[]) => (...input: any[]) => Promise<T>;
|
|
483
482
|
export declare const mirror: (s: any) => any;
|
|
484
483
|
export declare const reflect: (s: any) => any;
|
|
485
484
|
export declare const echo: (s: any) => any;
|
|
@@ -563,8 +562,46 @@ export declare const qomit: {
|
|
|
563
562
|
(a: string[]): (b: AnyObject) => any[] | AnyObject;
|
|
564
563
|
(a: string[], b: AnyObject): any[] | AnyObject;
|
|
565
564
|
};
|
|
565
|
+
/** @param start string | any[] @param s string | any[] */
|
|
566
|
+
export declare const qstartsWith: {
|
|
567
|
+
(a: symbol, b: string | any[]): (a: string | any[]) => boolean;
|
|
568
|
+
(a: string | any[], b: symbol): (b: string | any[]) => boolean;
|
|
569
|
+
(a: string | any[]): (b: string | any[]) => boolean;
|
|
570
|
+
(a: string | any[], b: string | any[]): boolean;
|
|
571
|
+
};
|
|
566
572
|
type StrTmpl = ((data: AnyObject) => string);
|
|
573
|
+
/** Supports ecrans: '\\{"json": {yes} \\}'
|
|
574
|
+
@returns get_tmpl(one{meme}two)({meme: 42}) -> one42two */
|
|
567
575
|
export declare const getTmpl: (tmpl: string) => StrTmpl;
|
|
576
|
+
/** One promise waits for another. */
|
|
577
|
+
export declare const forEachSerial: {
|
|
578
|
+
(a: symbol, b: any[]): (a: AnyFunc) => Promise<void>;
|
|
579
|
+
(a: AnyFunc, b: symbol): (b: any[]) => Promise<void>;
|
|
580
|
+
(a: AnyFunc): (b: any[]) => Promise<void>;
|
|
581
|
+
(a: AnyFunc, b: any[]): Promise<void>;
|
|
582
|
+
};
|
|
583
|
+
/** Promise.all wrapper for functional pipelining. */
|
|
584
|
+
export declare const waitAll: (promises: Promise<any>[]) => Promise<any[]>;
|
|
585
|
+
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
586
|
+
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
587
|
+
* @param {T} s - any value to tap and return back
|
|
588
|
+
* @returns {T}
|
|
589
|
+
*/
|
|
590
|
+
export declare const waitTap: {
|
|
591
|
+
(a: symbol, b: any): (a: AnyFunc) => Promise<any>;
|
|
592
|
+
(a: AnyFunc, b: symbol): (b: any) => Promise<any>;
|
|
593
|
+
(a: AnyFunc): (b: any) => Promise<any>;
|
|
594
|
+
(a: AnyFunc, b: any): Promise<any>;
|
|
595
|
+
};
|
|
596
|
+
/** Waits for all promises mapped by the fn. */
|
|
597
|
+
export declare const forEachAsync: {
|
|
598
|
+
(a: symbol, b: any[]): (a: (item: any) => Promise<any>) => Promise<any[]>;
|
|
599
|
+
(a: (item: any) => Promise<any>, b: symbol): (b: any[]) => Promise<any[]>;
|
|
600
|
+
(a: (item: any) => Promise<any>): (b: any[]) => Promise<any[]>;
|
|
601
|
+
(a: (item: any) => Promise<any>, b: any[]): Promise<any[]>;
|
|
602
|
+
};
|
|
603
|
+
/** The same as compose, but waits for promises in chains and returns a Promise. */
|
|
604
|
+
export declare const composeAsync: <T = any>(...fns: AnyFunc[]) => (...input: any[]) => Promise<T>;
|
|
568
605
|
|
|
569
606
|
export {
|
|
570
607
|
length$1 as length,
|
package/dist/bundle.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=Symbol("Placeholder"),r=r=>{let t=0;for(const n of r)n!==e&&t++;return t},t=(r,t)=>{const n=r.length,s=r.slice(),c=t.length;let o=c,i=0;for(;o&&i<n;i++)s[i]===e&&(s[i]=t[c-o],o--);for(i=n;o;i++,o--)s[i]=t[c-o];return s},n=(e,s,c)=>{const o=e.length-s.length-r(c);if(o<1)return e(...t(s,c));{const r=(...r)=>n(e,t(s,c),r);return r.$args_left=o,r}},s=e=>(...t)=>e.length>r(t)?n(e,[],t):e(...t);function c(r){return function(t,n){const s=t===e,c=arguments.length;if(1===c&&s)throw new Error("Senseless placeholder usage.");return c>1?s?(r=>function(t){return t===e?r:r(t)})((e=>r(e,n))):r(t,n):e=>r(t,e)}}function o(e){return s(e)}const i=void 0,
|
|
1
|
+
const e=Symbol("Placeholder"),r=r=>{let t=0;for(const n of r)n!==e&&t++;return t},t=(r,t)=>{const n=r.length,s=r.slice(),c=t.length;let o=c,i=0;for(;o&&i<n;i++)s[i]===e&&(s[i]=t[c-o],o--);for(i=n;o;i++,o--)s[i]=t[c-o];return s},n=(e,s,c)=>{const o=e.length-s.length-r(c);if(o<1)return e(...t(s,c));{const r=(...r)=>n(e,t(s,c),r);return r.$args_left=o,r}},s=e=>(...t)=>e.length>r(t)?n(e,[],t):e(...t);function c(r){return function(t,n){const s=t===e,c=arguments.length;if(1===c&&s)throw new Error("Senseless placeholder usage.");return c>1?s?(r=>function(t){return t===e?r:r(t)})((e=>r(e,n))):r(t,n):e=>r(t,e)}}function o(e){return s(e)}const i=void 0,u=1/0,l=e=>typeof e,a=e=>null===e,f=e=>"number"==l(e),h=e=>Array.isArray(e),b=e=>"function"===l(e),g=e=>!a(e)&&"object"===l(e),p={u:"U",b:"B",n:"N",s:"S",f:"F"},j=Symbol(),y=e=>e.toLowerCase(),d=e=>e.toUpperCase(),m=e=>{const r=l(e);return"object"===r?a(e)?"Null":e.constructor.name:p[r[0]]+r.slice(1)},O=c(((e,r)=>m(r)===e)),w=e=>e.length,A=e=>a(e)||(e=>e===i)(e),S=c(((e,r)=>e===r)),k=c(((e,r)=>{const t=m(e);if(S(t,m(r))&&(S(t,"Object")||S(t,"Array"))){if(a(e)||a(r))return S(e,r);if(S(e,r))return!0;for(const t of[e,r])for(const n in t)if(!(S(t,r)&&n in e||S(t,e)&&n in r&&k(e[n],r[n])))return!1;return!0}return S(e,r)})),v=c(((e,r)=>{if((e=>"string"===l(e))(r))return r.includes(e);for(const t of r)if(k(t,e))return!0;return!1})),N=e=>c(((r,t)=>{const n=w(r);if(n>w(t))return!1;for(let s=0;s<n;s++)if(!e(t[s],r[s]))return!1;return!0})),C=c(((e,r)=>(r.push(e),r))),E=o(((e,r,t)=>(t[e]=r,t))),P=o(((e,r,t)=>t.reduce(e,r))),$=o(((e,r,t)=>{for(let n in t)switch(m(t[n])){case"Array":if(e>1&&"Array"===m(r[n]))switch(e){case 2:const s=r[n],c=t[n];for(const r in c)s[r]?$(e,s[r],c[r]):s[r]=c[r];break;case 3:r[n].push(...t[n])}else r[n]=t[n];break;case"Object":if("Object"===m(r[n])){$(e,r[n],t[n]);break}default:r[n]=t[n]}return r})),x=$(1),z=$(2),B=$(3),U=c(((e,r)=>Object.assign(e,r))),_=c(((e,r)=>{let t,n,s,c;for(t in e)t in r&&(n=e[t],[s,c]=b(n)?n(r[t],t,r):[n,r[t]],r[A(s)?t:s]=c,t!==s&&delete r[t]);return r})),F=c(((e,r)=>{for(let t in r)r[t]=e(r[t],+t,r);return r})),I=c(((e,r)=>F(e,r))),L=c(((e,r)=>{const t=h(r);let n,s;t&&(n=0,s=[]);for(let n in r)e(r[n],n)||(t?s.push(+n):delete r[n]);if(t)for(const e of s)r.splice(e-n++,1);return r})),q=e=>{if(h(e))e.splice(0);else for(const r in e)delete e[r];return e},D=e=>{let r;for(const t in e)r=e[t],g(r)&&D(r);return Object.freeze(e)},G=e=>Object.freeze(e),H=c(((e,r)=>r.unshift(e))),J=o(((e,r,t)=>{const n=e[0];return E(n,e.length<2?r:J(e.slice(1),r,g(t[n])?t[n]:{}),t)})),K=e=>e.reverse(),M=c(((e,r)=>L(((r,t)=>!v(t,e)),r))),Q=N(S),R=e=>(...r)=>P(((e,r)=>e?e(r):e),e,r),T=e=>(...r)=>r[e],V=c(((e,r)=>e==r)),W=s(((e,r,t,n)=>e(n)?r(n):t(n))),X=o(((e,r,t)=>W(e,r,de,t))),Y=(...r)=>(...t)=>{let n,s=!0;for(let c=w(r)-1;c>-1;c--)s?(s=!1,n=r[c](...t)):n=n===e?r[c]():r[c](n);return n},Z=c(((e,r)=>e.bind(r))),ee=c(((e,r)=>r[e])),re=o(((e,r,t)=>t.slice(e,f(r)?r:u))),te=e=>c(((r,t)=>e(t,r))),ne=ee(0),se=re(1,u),ce=c(((e,r)=>e+r)),oe=c(((e,r)=>r-e)),ie=c(((e,r)=>e*r)),ue=c(((e,r)=>e<r)),le=c(((e,r)=>e>r)),ae=c(((e,r)=>e<=r)),fe=c(((e,r)=>e>=r)),he=c(((e,r)=>r.sort(e))),be=c(((e,r)=>r.find(e))),ge=c(((e,r)=>r.findIndex(e))),pe=c(((e,r)=>ge(k(e),r))),je=c(((e,r)=>e/r)),ye=e=>()=>e,de=e=>e,me=e=>e.trim(),Oe=e=>e[w(e)-1],we=N(((e,r)=>k(e,r))),Ae=e=>!e,Se=e=>Object.keys(e),ke=e=>Object.values(e),ve=e=>Object.entries(e),Ne=c(((e,r)=>e.test(r))),Ce=c(((e,r)=>(e(r),r))),Ee=c(((e,r)=>[...r,e])),Pe=c(((e,r)=>[...r,e])),$e=e=>e.flat(u),xe=e=>e.flat(),ze=c(((e,r)=>r.flat(e))),Be=c(((e,r)=>r.split(e))),Ue=ye(!0),_e=ye(!1),Fe=c(((e,r)=>r(...e))),Ie=()=>{},Le=s(((e,r,t)=>t[r](...e))),qe=e=>(...r)=>{const t=e(...r),n=b(t);return!n||n&&t.$args_left<=0?Ae(t):qe(t)},De=e=>{if("Object"===m(e)){let r=0;for(let t in e)r++;return r}return w(e)},Ge=c(((e,r)=>Ke(ce(e),r-e))),He=e=>P(((e,r)=>be(k(r),e)?e:C(r,e)),[],e),Je=c(((e,r)=>e.filter(te(v)(r)))),Ke=c(((e,r)=>[...Array(r)].map(((r,t)=>e(t))))),Me=e=>{let r,t=!1;return(...n)=>t?r:(t=!0,r=e(...n))},Qe=e=>Y((r=>gr(((t,n,s)=>C(e[r-s],t)),[],e)),ce(-1),w)(e),Re=(e,r="log")=>Ce((t=>console[r](e,t))),Te=c(((e,r)=>{for(const[t,n]of e)if(t(r))return n(r)})),Ve=o(((e,r,t)=>({...t,[e]:r}))),We=o(((e,r,t)=>Y((n=>Ve(n,w(e)<2?r:We(re(1,u,e),r,g(t[n])?t[n]:{}),t)),ne)(e))),Xe=c(((e,r)=>r.every(e))),Ye=c(((e,r)=>r.some(e))),Ze=c(((e,r)=>e.every((e=>e(r))))),er=c(((e,r)=>e.some((e=>e(r))))),rr=c(((e,r)=>r[e])),tr=o(((e,r,t)=>k(t[e],r))),nr=o(((e,r,t)=>k(r[e],t[e]))),sr=o(((e,r,t)=>w(r)?A(t)?e:Y((n=>n in t?sr(e,re(1,u,r),t[n]):e),ne)(r):t)),cr=sr(i),or=o(((e,r,t)=>k(cr(e,t),r))),ir=o(((e,r,t)=>k(cr(e,r),cr(e,t)))),ur=Y(W(k(j),_e,Ue),sr(j)),lr=/^(.*?)(8|16|32|64)(Clamped)?Array$/,ar=(e,r=!1)=>{const t=m(e);switch(t){case"Null":case"String":case"Number":case"Boolean":case"Symbol":return e;case"Array":return r?[...e]:Or(Y(ar,T(0)),e);case"Object":if(r)return{...e};const n={};for(let r in e)n[r]=ar(e[r]);return n;default:return lr.test(t)?e.constructor.from(e):e}},fr=e=>ar(e,!0),hr=e=>D(ar(e)),br=e=>G(ar(e)),gr=o(((e,r,t)=>P(e,ar(r),t))),pr=c(((e,r)=>Er(e,r))),jr=c(((e,r)=>{const t={};for(const n of e)n in r&&(t[n]=r[n]);return t})),yr=c(((e,r)=>Er(((r,t)=>!v(t,e)),r))),dr=e=>Object.fromEntries(e),mr=c(((e,r)=>r.concat(e))),Or=c(((e,r)=>r.map(e))),wr=c(((e,r)=>I(e,fr(r)))),Ar=c(((e,r)=>r.join(e))),Sr=c(((e,r)=>r.forEach(e))),kr=o(((e,r,t)=>r(t)&&e(t))),vr=e=>{switch(m(e)){case"String":case"Array":return 0==w(e);case"Object":for(const r in e)return!1;return!0;default:return null}},Nr=e=>{switch(m(e)){case"String":return"";case"Object":return{};case"Array":return[];default:return i}},Cr=o(((e,r,t)=>t.replace(e,r))),Er=c(((e,r)=>h(r)?r.filter(e):L(e,{...r}))),Pr=e=>{let r,t=!1;return()=>t?r:(t=!0,r=e())},$r=c(((e,r)=>Object.assign({},e,r))),xr=c(((e,r)=>x(ar(e),ar(r)))),zr=c(((e,r)=>z(ar(e),ar(r)))),Br=c(((e,r)=>B(ar(e),ar(r)))),Ur=o(((e,r,t)=>Ve(e,r(t[e]),t))),_r=c(((e,r)=>_(e,Object.assign({},r)))),Fr=c(((e,r)=>Or(((e,t)=>[e,r[t]]),e))),Ir=c(((e,r)=>gr(((e,t,n)=>Ve(t,r[n],e)),{},e))),Lr=o(((e,r,t)=>Or(((r,n)=>e(r,t[n])),r))),qr=de,Dr=de,Gr=de,Hr=qe,Jr=Ee,Kr=Ye,Mr=e=>{const r=[],t=[],n=e.length;let s,c,o,i=0,u=0,l=!1,a=ne(e),f=!1;for(i=0;i<n;i++)switch(s=e[i],s){case"{":if(!a){l=!0,u=i;break}case"}":if(!a){l=!1,r.push(""),t.push(e.slice(u+1,i));break}default:o=e[i+1],f="\\"===s,l||f&&("{"===o||"}"===o)||(c=r.length-1,c<0&&(r.push(""),c++),r[c]+=s),a=f}return e=>{const n=[],s=r.length-1;for(const c in r)i=+c,n.push(r[i]),i!==s&&n.push(cr(t[i].split("."),e));return n.join("")}},Qr=(()=>{const e=async(r,t,n)=>{n<t.length&&(await r(t[n]),await e(r,t,++n))};return c(((r,t)=>e(r,t,0)))})(),Rr=e=>Promise.all(e),Tr=c((async(e,r)=>(await e(r),r))),Vr=c(((e,r)=>Promise.all(r.map(e)))),Wr=(()=>{const e=async(r,t,n)=>~n?await e(r,[await r[n](...t)],--n):ne(t);return(...r)=>(...t)=>e(r,t,r.length-1)})();export{_e as F,Ue as T,e as __,ce as add,Xe as all,Ze as allPass,ye as always,Ye as any,er as anyPass,Ee as append,Ve as assoc,We as assocPath,Z as bind,kr as both,Le as callFrom,Fe as callWith,ar as clone,fr as cloneShallow,qe as complement,Y as compose,Wr as composeAsync,mr as concat,Te as cond,s as curry,c as curry2,o as curry3,je as divide,Gr as echo,Nr as empty,S as eq,k as equals,Re as explore,Er as filter,be as find,ge as findIndex,$e as flat,xe as flatShallow,ze as flatTo,te as flip,Sr as forEach,Vr as forEachAsync,Qr as forEachSerial,hr as freeze,br as freezeShallow,dr as fromPairs,Ke as genBy,Mr as getTmpl,ue as gt,ae as gte,ne as head,de as identity,W as ifElse,v as includes,pe as indexOf,Je as intersection,vr as isEmpty,A as isNil,Ar as join,Se as keys,Oe as last,w as length,le as lt,fe as lte,Or as map,_r as mapKeys,wr as mapObj,Pr as memoize,xr as mergeDeep,Br as mergeDeepAdd,zr as mergeDeepX,$r as mergeShallow,qr as mirror,ie as multiply,Ie as noop,Ae as not,Hr as notf,ee as nth,yr as omit,Me as once,Ur as overProp,cr as path,or as pathEq,ur as pathExists,sr as pathOr,ir as pathsEq,jr as pick,pr as pickBy,Pe as prepend,rr as prop,tr as propEq,nr as propsEq,Jr as push,C as qappend,E as qassoc,J as qassocPath,q as qempty,L as qfilter,D as qfreeze,G as qfreezeShallow,F as qmap,_ as qmapKeys,I as qmapObj,x as qmergeDeep,B as qmergeDeepAdd,z as qmergeDeepX,U as qmergeShallow,M as qomit,H as qprepend,P as qreduce,K as qreverse,Q as qstartsWith,N as qstartsWithWith,Ge as range,gr as reduce,Dr as reflect,Cr as replace,Qe as reverse,De as sizeof,re as slice,Kr as some,he as sort,Be as split,we as startsWith,oe as subtract,j as symbol,se as tail,T as take,Ce as tap,Ne as test,y as toLower,ve as toPairs,d as toUpper,me as trim,m as type,O as typeIs,R as uncurry,He as uniq,ke as values,Rr as waitAll,Tr as waitTap,V as weakEq,X as when,Fr as zip,Ir as zipObj,Lr as zipWith};
|
package/package.json
CHANGED
package/src/async.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { curry2 } from "./curry"
|
|
2
|
+
import { head } from "./safe"
|
|
3
|
+
import { AnyFunc } from "./types"
|
|
4
|
+
|
|
5
|
+
/** One promise waits for another. */
|
|
6
|
+
export const forEachSerial = (() => {
|
|
7
|
+
const pipe = async (fn: AnyFunc, items: any[], i: number) => {
|
|
8
|
+
if(i<items.length) {
|
|
9
|
+
await fn(items[i])
|
|
10
|
+
await pipe(fn, items, ++i)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return curry2(
|
|
14
|
+
(fn: AnyFunc, items: any[]) => pipe(fn, items, 0)
|
|
15
|
+
)
|
|
16
|
+
})()
|
|
17
|
+
/** Promise.all wrapper for functional pipelining. */
|
|
18
|
+
export const waitAll = (promises: Promise<any>[]) => Promise.all(promises)
|
|
19
|
+
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
20
|
+
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
21
|
+
* @param {T} s - any value to tap and return back
|
|
22
|
+
* @returns {T}
|
|
23
|
+
*/
|
|
24
|
+
export const waitTap = curry2(async (fn: AnyFunc, s: any) => { await fn(s); return s })
|
|
25
|
+
/** Waits for all promises mapped by the fn. */
|
|
26
|
+
export const forEachAsync = curry2(
|
|
27
|
+
(fn: (item: any) => Promise<any>, items: any[]) =>
|
|
28
|
+
Promise.all(items.map(fn))
|
|
29
|
+
)
|
|
30
|
+
/** The same as compose, but waits for promises in chains and returns a Promise. */
|
|
31
|
+
export const composeAsync = (() => {
|
|
32
|
+
const pipe = async (fns: AnyFunc[], input: any[], i: number): Promise<any> =>
|
|
33
|
+
~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input)
|
|
34
|
+
return <T = any>(...fns: AnyFunc[]) =>
|
|
35
|
+
(...input: any[]) => pipe(fns, input, fns.length-1) as Promise<T>
|
|
36
|
+
})()
|
package/src/common.ts
CHANGED
|
@@ -1,18 +1,54 @@
|
|
|
1
1
|
import { curry2 } from "./curry"
|
|
2
|
-
import {
|
|
2
|
+
import { BasicType } from "./types"
|
|
3
|
+
import { to, isNull, isStr, isUndef } from "./utils"
|
|
3
4
|
|
|
4
5
|
// It's faster that toUpperCase() !
|
|
5
|
-
const caseMap = {
|
|
6
|
-
u: 'U', b: 'B', n: 'N', s: 'S', f: 'F'
|
|
7
|
-
}
|
|
6
|
+
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F' }
|
|
8
7
|
|
|
9
8
|
export const symbol = Symbol()
|
|
10
9
|
export const toLower = (s: string) => s.toLowerCase()
|
|
11
10
|
export const toUpper = (s: string) => s.toUpperCase()
|
|
12
|
-
export const type = (s: any) => {
|
|
11
|
+
export const type = (s: any): string => {
|
|
13
12
|
const t = to(s)
|
|
14
13
|
return t==='object'
|
|
15
14
|
? isNull(s) ? 'Null' : s.constructor.name
|
|
16
15
|
: caseMap[t[0]] + t.slice(1)
|
|
17
16
|
}
|
|
18
|
-
export const typeIs = curry2((t: string, s: any) => type(s)===t)
|
|
17
|
+
export const typeIs = curry2((t: string, s: any) => type(s)===t)
|
|
18
|
+
export const length = (s: any[] | string) => s.length
|
|
19
|
+
export const isNil = (s: any) => isNull(s) || isUndef(s)
|
|
20
|
+
export const eq = curry2((a: any, b: any) => a===b)
|
|
21
|
+
export const equals = curry2((a: any, b: any) => {
|
|
22
|
+
const typea = type(a)
|
|
23
|
+
if(eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array'))) {
|
|
24
|
+
if(isNull(a) || isNull(b)) return eq(a, b)
|
|
25
|
+
if(eq(a, b)) return true
|
|
26
|
+
for(const v of [a, b])
|
|
27
|
+
for(const k in v)
|
|
28
|
+
if(
|
|
29
|
+
!((eq(v, b)) && (k in a)) &&
|
|
30
|
+
!((eq(v, a)) && (k in b) && equals(a[k], b[k]))
|
|
31
|
+
) return false
|
|
32
|
+
return true
|
|
33
|
+
}
|
|
34
|
+
return eq(a, b)
|
|
35
|
+
})
|
|
36
|
+
export const includes = curry2(
|
|
37
|
+
<T>(s: T, ss: T[]) => {
|
|
38
|
+
if(isStr(ss)) return ss.includes(s)
|
|
39
|
+
else {
|
|
40
|
+
for(const a of ss) if(equals(a, s)) return true
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
/** @param start string | any[] @param s string | any[] */
|
|
46
|
+
export const qstartsWithWith = (comparator: (x: any, y: any)=>boolean) => curry2(
|
|
47
|
+
(start: any[] | string, s: any[] | string) => {
|
|
48
|
+
const len_start = length(start)
|
|
49
|
+
const len_s = length(s)
|
|
50
|
+
if(len_start>len_s) return false
|
|
51
|
+
for(let i=0; i<len_start; i++) if(!comparator(s[i], start[i])) return false
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
)
|
package/src/index.ts
CHANGED
package/src/quick.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { curry2, curry3 } from "./curry"
|
|
2
|
-
import { type } from "./common"
|
|
2
|
+
import { includes, isNil, type, length, eq, qstartsWithWith } from "./common"
|
|
3
3
|
import { AnyObject, Reducer, AnyFunc } from "./types"
|
|
4
4
|
import { isFunc, isArray, isObj } from "./utils"
|
|
5
|
-
|
|
6
|
-
// TODO: qoverProp, qover array ?
|
|
5
|
+
// TODO: qflat, qoverProp, qover array ?
|
|
7
6
|
|
|
8
7
|
export const qappend = curry2((s: any, xs: any[]) => {xs.push(s); return xs})
|
|
9
8
|
export const qassoc = curry3((prop: string, v: any, obj: AnyObject) => { obj[prop] = v; return obj })
|
|
@@ -91,7 +90,7 @@ export const qfilter = curry2(
|
|
|
91
90
|
}
|
|
92
91
|
)
|
|
93
92
|
export const qempty = (o: AnyObject|any[]) => {
|
|
94
|
-
if(isArray(o)) o.splice(0)
|
|
93
|
+
if(isArray(o)) o.splice(0)
|
|
95
94
|
else for(const i in o) delete o[i]
|
|
96
95
|
return o
|
|
97
96
|
}
|
|
@@ -119,4 +118,6 @@ export const qomit = curry2(
|
|
|
119
118
|
(_: any, k: string) => !includes(k, props),
|
|
120
119
|
o
|
|
121
120
|
)
|
|
122
|
-
)
|
|
121
|
+
)
|
|
122
|
+
/** @param start string | any[] @param s string | any[] */
|
|
123
|
+
export const qstartsWith = qstartsWithWith(eq)
|
package/src/safe.ts
CHANGED
|
@@ -1,28 +1,12 @@
|
|
|
1
1
|
import { __, curry, curry2, curry3 } from './curry'
|
|
2
|
-
import { isNum,
|
|
2
|
+
import { isNum, undef, isNull, isArray, isFunc, isObj, inf } from './utils'
|
|
3
3
|
import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd, qfilter, qfreeze, qfreezeShallow, qmapObj } from './quick'
|
|
4
4
|
import { AnyFunc, Cond, AnyObject, Reducer } from './types'
|
|
5
|
-
import { symbol, type } from './common'
|
|
5
|
+
import { symbol, type, length, equals, includes, isNil, qstartsWithWith } from './common'
|
|
6
6
|
// over, lensProp
|
|
7
7
|
|
|
8
8
|
export const take = (argN: number) => (...args: any[]) => args[argN]
|
|
9
|
-
export const eq = curry2((a: any, b: any) => a===b)
|
|
10
9
|
export const weakEq = curry2((a: any, b: any) => a==b)
|
|
11
|
-
export const equals = curry2((a: any, b: any) => {
|
|
12
|
-
const typea = type(a)
|
|
13
|
-
if(eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array'))) {
|
|
14
|
-
if(isNull(a) || isNull(b)) return eq(a, b)
|
|
15
|
-
if(eq(a, b)) return true
|
|
16
|
-
for(const v of [a, b])
|
|
17
|
-
for(const k in v)
|
|
18
|
-
if(
|
|
19
|
-
!((eq(v, b)) && (k in a)) &&
|
|
20
|
-
!((eq(v, a)) && (k in b) && equals(a[k], b[k]))
|
|
21
|
-
) return false
|
|
22
|
-
return true
|
|
23
|
-
}
|
|
24
|
-
return eq(a, b)
|
|
25
|
-
})
|
|
26
10
|
export const ifElse = curry(
|
|
27
11
|
(
|
|
28
12
|
cond: (s: any) => boolean,
|
|
@@ -58,15 +42,6 @@ export const bind = curry2<AnyFunc>(
|
|
|
58
42
|
(fn: AnyFunc, context: any) => fn.bind(context)
|
|
59
43
|
)
|
|
60
44
|
export const nth = curry2(<T=any>(i: number, data: T[] | string) => data[i])
|
|
61
|
-
export const includes = curry2(
|
|
62
|
-
<T>(s: T, ss: T[]) => {
|
|
63
|
-
if(isStr(ss)) return ss.includes(s)
|
|
64
|
-
else {
|
|
65
|
-
for(const a of ss) if(equals(a, s)) return true
|
|
66
|
-
return false
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
)
|
|
70
45
|
export const slice = curry3(
|
|
71
46
|
(from: number, to: number, o: any[] | string) =>
|
|
72
47
|
o.slice(from, (isNum(to)?to:inf) as number)
|
|
@@ -74,26 +49,35 @@ export const slice = curry3(
|
|
|
74
49
|
export const flip = <T extends AnyFunc>(fn: T) => curry2(
|
|
75
50
|
(b: Parameters<T>[1], a: Parameters<T>[0]) => fn(a, b)
|
|
76
51
|
)
|
|
52
|
+
/** @returns first element of an array. */
|
|
77
53
|
export const head = nth(0) as <T = any>(xs: T[] | string) => T
|
|
54
|
+
/** @returns last element of an array. */
|
|
78
55
|
export const tail = slice(1, inf)
|
|
79
|
-
|
|
80
|
-
export const
|
|
81
|
-
|
|
82
|
-
export const
|
|
83
|
-
|
|
84
|
-
export const
|
|
85
|
-
|
|
56
|
+
/** @param a @param b @returns a+b */
|
|
57
|
+
export const add = curry2((a: number, b: number) => a+b)
|
|
58
|
+
/** @param a @param b @returns b-a */
|
|
59
|
+
export const subtract = curry2((a: number, b: number) => b-a)
|
|
60
|
+
/**@param a @param b @returns a*b */
|
|
61
|
+
export const multiply = curry2((a: number, b: number) => a*b)
|
|
62
|
+
/** @param a @param b @returns a<b */
|
|
63
|
+
export const gt = curry2( (a: number, b: number) => a<b )
|
|
64
|
+
/** @param a @param b @returns a>b */
|
|
65
|
+
export const lt = curry2( (a: number, b: number) => a>b )
|
|
66
|
+
/** @param a @param b @returns a<=b */
|
|
67
|
+
export const gte = curry2( (a: number, b: number) => a<=b )
|
|
68
|
+
/** @param a @param b @returns a>=b */
|
|
69
|
+
export const lte = curry2( (a: number, b: number) => a>=b )
|
|
86
70
|
export const sort = curry2((sortFn: any, xs: any[]) => xs.sort(sortFn))
|
|
87
71
|
export const find = curry2((fn: Cond, s: any[]) => s.find(fn))
|
|
88
72
|
export const findIndex = curry2((fn: Cond, s: any[]) => s.findIndex(fn))
|
|
89
73
|
export const indexOf = curry2((x: any, xs: any[]) => findIndex(equals(x), xs))
|
|
90
74
|
export const divide = curry2((n: number, m: number) => n/m)
|
|
91
|
-
export const isNil = (s: any) => isNull(s) || isUndef(s)
|
|
92
|
-
export const length = (s: any[] | string) => s.length
|
|
93
75
|
export const always = <T=any>(s: T) => () => s
|
|
94
76
|
export const identity = (s: any) => s
|
|
95
77
|
export const trim = (s: string) => s.trim()
|
|
96
78
|
export const last = (s: any[] | string) => s[length(s)-1]
|
|
79
|
+
/** @param start string | any[] @param s string | any[] */
|
|
80
|
+
export const startsWith = qstartsWithWith((x: any, y: any) => equals(x, y))
|
|
97
81
|
type NotOverload = {
|
|
98
82
|
(x: true): false
|
|
99
83
|
(x: false): true
|
|
@@ -139,13 +123,11 @@ export const sizeof = (s: any[] | string | AnyObject) => {
|
|
|
139
123
|
return len
|
|
140
124
|
} else return length(s as any[])
|
|
141
125
|
}
|
|
142
|
-
export const range = curry2((from: number, to: number) =>
|
|
143
|
-
|
|
144
|
-
)
|
|
145
|
-
// TODO: make it using equals for deep stuff !
|
|
126
|
+
export const range = curry2((from: number, to: number) => genBy(add(from), to-from))
|
|
127
|
+
/** @param xs any[] @returns xs without duplicates. */
|
|
146
128
|
export const uniq = (xs: any[]) => qreduce(
|
|
147
129
|
<T>(accum: any, x: T) =>
|
|
148
|
-
|
|
130
|
+
find(equals(x), accum) ? accum : qappend(x, accum),
|
|
149
131
|
[], xs)
|
|
150
132
|
export const intersection = curry2(
|
|
151
133
|
(xs1: any[], xs2: any[]) => xs1.filter(flip(includes)(xs2))
|
|
@@ -177,11 +159,7 @@ export const explore = (caption: string, level = 'log') => tap(
|
|
|
177
159
|
)
|
|
178
160
|
export const cond = curry2(
|
|
179
161
|
(pairs: [Cond, Function][], s: any) => {
|
|
180
|
-
for(const [cond, fn] of pairs)
|
|
181
|
-
if(cond(s)) {
|
|
182
|
-
return fn(s)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
162
|
+
for(const [cond, fn] of pairs) if(cond(s)) return fn(s)
|
|
185
163
|
}
|
|
186
164
|
)
|
|
187
165
|
/** Assigns a prop to an object.
|
|
@@ -190,10 +168,7 @@ export const cond = curry2(
|
|
|
190
168
|
* @param object AnyObject
|
|
191
169
|
*/
|
|
192
170
|
export const assoc = curry3(
|
|
193
|
-
(prop: string, v: any, obj: AnyObject) => ({
|
|
194
|
-
...obj,
|
|
195
|
-
[prop]: v
|
|
196
|
-
})
|
|
171
|
+
(prop: string, v: any, obj: AnyObject) => ({...obj, [prop]: v})
|
|
197
172
|
)
|
|
198
173
|
export const assocPath = curry3(
|
|
199
174
|
(_path: string[], v: any, o: AnyObject) => compose(
|
|
@@ -209,16 +184,15 @@ export const assocPath = curry3(
|
|
|
209
184
|
)
|
|
210
185
|
export const all = curry2((pred: Cond, xs: any[]) => xs.every(pred))
|
|
211
186
|
export const any = curry2((pred: Cond, xs: any[]) => xs.some(pred))
|
|
212
|
-
export const allPass = curry2(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
export const
|
|
216
|
-
|
|
217
|
-
)
|
|
218
|
-
export const prop = curry2( (key: string, o: AnyObject) => o[key] )
|
|
187
|
+
export const allPass = curry2((preds: Cond[], x: any) => preds.every((pred) => pred(x)))
|
|
188
|
+
export const anyPass = curry2((preds: Cond[], x: any) => preds.some((pred) => pred(x)))
|
|
189
|
+
/** @param key string @param o AnyObject @returns o[key] */
|
|
190
|
+
export const prop = curry2((key: string, o: AnyObject) => o[key])
|
|
191
|
+
/** @param key string @param value any @param o AnyObject @returns o[key] equals value */
|
|
219
192
|
export const propEq = curry3(
|
|
220
193
|
(key: string, value: any, o: AnyObject) => equals(o[key], value)
|
|
221
194
|
)
|
|
195
|
+
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
222
196
|
export const propsEq = curry3(
|
|
223
197
|
(key: string, o1: any, o2: AnyObject) => equals(o1[key], o2[key])
|
|
224
198
|
)
|
|
@@ -295,21 +269,15 @@ type Concat = ((a: string, b: string) => string)
|
|
|
295
269
|
export const concat = curry2(
|
|
296
270
|
((a: any, b: string | any[]) => b.concat(a)) as Concat
|
|
297
271
|
)
|
|
298
|
-
export const join = curry2(
|
|
299
|
-
(delimeter: string, arr: string[]) => arr.join(delimeter)
|
|
300
|
-
)
|
|
301
272
|
export const map = curry2(
|
|
302
273
|
(pipe: (s: any, i?: number, list?: any[]) => any, arr: any[]) => arr.map(pipe)
|
|
303
274
|
)
|
|
304
275
|
export const mapObj = curry2(
|
|
305
276
|
(pipe: (s: any, i?: string, list?: any[]) => any, o: AnyObject) => qmapObj(pipe, cloneShallow(o))
|
|
306
277
|
)
|
|
307
|
-
export const
|
|
308
|
-
|
|
309
|
-
)
|
|
310
|
-
export const both = curry3(
|
|
311
|
-
(cond1: Cond, cond2: Cond, s: any) => cond2(s) && cond1(s)
|
|
312
|
-
)
|
|
278
|
+
export const join = curry2((delimeter: string, arr: string[]) => arr.join(delimeter))
|
|
279
|
+
export const forEach = curry2((pipe: (s: any) => any, arr: any[]) => arr.forEach(pipe))
|
|
280
|
+
export const both = curry3((cond1: Cond, cond2: Cond, s: any) => cond2(s) && cond1(s))
|
|
313
281
|
export const isEmpty = (s: any) => {
|
|
314
282
|
switch(type(s)) {
|
|
315
283
|
case 'String': case 'Array': return length(s)==0
|
|
@@ -392,40 +360,8 @@ export const zipWith = curry3(
|
|
|
392
360
|
map((s: T1, i: number) => pipe(s, b[i]), a)
|
|
393
361
|
)
|
|
394
362
|
|
|
395
|
-
//
|
|
396
|
-
|
|
397
|
-
/** One promise waits for another. */
|
|
398
|
-
export const forEachSerial = (() => {
|
|
399
|
-
const pipe = async (fn: AnyFunc, items: any[], i: number) => {
|
|
400
|
-
if(i<items.length) {
|
|
401
|
-
await fn(items[i])
|
|
402
|
-
await pipe(fn, items, ++i)
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return curry2(
|
|
406
|
-
(fn: AnyFunc, items: any[]) => pipe(fn, items, 0)
|
|
407
|
-
)
|
|
408
|
-
})()
|
|
409
|
-
/** Promise.all wrapper for functional pipelining. */
|
|
410
|
-
export const waitAll = (promises: Promise<any>[]) => Promise.all(promises)
|
|
411
|
-
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
412
|
-
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
413
|
-
* @param {T} s - any value to tap and return back
|
|
414
|
-
* @returns {T}
|
|
415
|
-
*/
|
|
416
|
-
export const waitTap = curry2(async (fn: AnyFunc, s: any) => { await fn(s); return s })
|
|
417
|
-
/** Waits for all promises mapped by the fn. */
|
|
418
|
-
export const forEachAsync = curry2(
|
|
419
|
-
(fn: (item: any) => Promise<any>, items: any[]) =>
|
|
420
|
-
Promise.all(items.map(fn))
|
|
421
|
-
)
|
|
422
|
-
/** The same as compose, but waits for promises in chains and returns a Promise. */
|
|
423
|
-
export const composeAsync = (() => {
|
|
424
|
-
const pipe = async (fns: AnyFunc[], input: any[], i: number): Promise<any> =>
|
|
425
|
-
~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input)
|
|
426
|
-
return <T = any>(...fns: AnyFunc[]) =>
|
|
427
|
-
(...input: any[]) => pipe(fns, input, fns.length-1) as Promise<T>
|
|
428
|
-
})()
|
|
363
|
+
// Reexport safe stuff that is ready to use externally.
|
|
364
|
+
export { toLower, toUpper, type, typeIs, length, isNil, eq, equals, includes } from './common'
|
|
429
365
|
|
|
430
366
|
// ALIASES
|
|
431
367
|
export const mirror = identity
|
package/src/strings.ts
CHANGED
|
@@ -5,8 +5,8 @@ type StrTmpl = ((data: AnyObject) => string)
|
|
|
5
5
|
const ecran = '\\'
|
|
6
6
|
|
|
7
7
|
// TODO: make it splicy, not accumulatie by symbols.
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/** Supports ecrans: '\\{"json": {yes} \\}'
|
|
9
|
+
@returns get_tmpl(one{meme}two)({meme: 42}) -> one42two */
|
|
10
10
|
export const getTmpl = (tmpl: string): StrTmpl => {
|
|
11
11
|
const parts: string[] = []
|
|
12
12
|
const keymap: string[] = []
|
package/src/types.ts
CHANGED
|
@@ -7,4 +7,5 @@ export type TupleFn<ARG1=any, ARG2=any, Out=any> = (a: ARG1, b: ARG2) => Out
|
|
|
7
7
|
export type Curried<
|
|
8
8
|
Args extends AnyArgs = AnyArgs,
|
|
9
9
|
ReturnT = any
|
|
10
|
-
> = (arg: Args[number]) => Curried<Args> | ReturnT
|
|
10
|
+
> = (arg: Args[number]) => Curried<Args> | ReturnT
|
|
11
|
+
export type BasicType = 'String'|'Object'|'Number'|'Symbol'|'Array'|'Null'|'Undefined'
|