pepka 1.0.0-beta.2 → 1.0.0-beta.3
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 +64 -61
- package/dist/bundle.mjs +1 -1
- package/package.json +1 -1
- package/src/quick.ts +20 -33
- package/src/safe.ts +36 -53
package/dist/bundle.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=Symbol("Placeholder"),r=r=>{let t=0;for(const s of r)s!==e&&t++;return t},t=(r,t)=>{const s=r.length,o=r.slice(),p=t.length;let n=p,
|
|
1
|
+
"use strict";const e=Symbol("Placeholder"),r=r=>{let t=0;for(const s of r)s!==e&&t++;return t},t=(r,t)=>{const s=r.length,o=r.slice(),p=t.length;let n=p,c=0;for(;n&&c<s;c++)o[c]===e&&(o[c]=t[p-n],n--);for(c=s;n;c++,n--)o[c]=t[p-n];return o},s=(e,o,p)=>{const n=e.length-o.length-r(p);if(n<1)return e(...t(o,p));{const r=(...r)=>s(e,t(o,p),r);return r.$args_left=n,r}},o=e=>(...t)=>e.length>r(t)?s(e,[],t):e(...t),p=r=>function(t){return t===e?r:r(t)};function n(r){return function(t,s){const o=t===e,n=arguments.length;if(1===n&&o)throw new Error("Senseless placeholder usage.");return arguments.length>1?o?p((e=>r(e,s))):r(t,s):e=>r(t,e)}}function c(e){return o(e)}const x=void 0,a=1/0,i=e=>typeof e,l=e=>null===e,u=e=>"number"==i(e),f=e=>Array.isArray(e),h=e=>"function"===i(e),m={u:"U",b:"B",n:"N",s:"S",f:"F"},y=e=>{const r=i(e);return"object"===r?l(e)?"Null":e.constructor.name:m[r[0]]+r.slice(1)},d=n(((e,r)=>y(r)===e)),g=n(((e,r)=>(r.push(e),r))),b=c(((e,r,t)=>(t[e]=r,t))),w=c(((e,r,t)=>t.reduce(e,r))),j=c(((e,r,t)=>{for(let s in t)switch(y(t[s])){case"Array":if(e>1&&"Array"===y(r[s]))switch(e){case 2:const o=r[s],p=t[s];for(const r in p)o[r]?j(e,o[r],p[r]):o[r]=p[r];break;case 3:r[s].push(...t[s])}else r[s]=t[s];break;case"Object":if("Object"===y(r[s])){j(e,r[s],t[s]);break}default:r[s]=t[s]}return r})),O=j(1),q=j(2),A=j(3),E=n(((e,r)=>Object.assign(e,r))),S=n(((e,r)=>{let t,s,o,p;for(t in e)s=e[t],[o,p]=h(s)?s(r):[s,r[t]],r[o]=p,t!==o&&delete r[t];return r})),k=n(((e,r)=>{for(let t in r)r[t]=e(r[t],+t,r);return r})),v=n(((e,r)=>{const t=f(r);let s,o;t&&(s=0,o=[]);for(let s in r)e(r[s],s)||(t?o.push(+s):delete r[s]);if(t)for(const e of o)r.splice(e-s++,1);return r})),P=e=>(...r)=>r[e],D=n(((e,r)=>{const t=y(e);if(t===y(r)&&("Object"===t||"Array"==t)){if(l(e)||l(r))return e===r;if(e===r)return!0;for(const t of[e,r])for(const s in t)if(!(t===r&&s in e||t===e&&s in r&&D(e[s],r[s])))return!1;return!0}return e===r})),z=o(((e,r,t,s)=>e(s)?r(s):t(s))),N=c(((e,r,t)=>z(e,r,te,t))),B=(...r)=>(...t)=>{let s,o=!0;for(let p=ee(r)-1;p>-1;p--)o?(o=!1,s=r[p](...t)):s=s===e?r[p]():r[p](s);return s},_=n(((e,r)=>e.bind(r))),C=n(((e,r)=>r[e])),I=n(((e,r)=>{if((e=>"string"===i(e))(r))return r.includes(e);for(const t of r)if(D(t,e))return!0;return!1})),T=c(((e,r,t)=>t.slice(e,u(r)?r:a))),U=e=>n(((r,t)=>e(t,r))),$=C(0),F=T(1,a),K=n(((e,r)=>e+r)),L=n(((e,r)=>r-e)),W=n(((e,r)=>e*r)),X=n(((e,r)=>e>r)),G=n(((e,r)=>e<r)),H=n(((e,r)=>r>=e)),J=n(((e,r)=>r<=e)),M=n(((e,r)=>r.sort(e))),Q=n(((e,r)=>r.find(e))),R=n(((e,r)=>r.findIndex(e))),V=n(((e,r)=>R(D(e),r))),Y=n(((e,r)=>e/r)),Z=e=>l(e)||(e=>e===x)(e),ee=e=>e.length,re=e=>()=>e,te=e=>e,se=e=>!e,oe=n(((e,r)=>e.test(r))),pe=n(((e,r)=>(e(r),r))),ne=n(((e,r)=>[...r,e])),ce=n(((e,r)=>r.split(e))),xe=re(!0),ae=re(!1),ie=n(((e,r)=>r(...e))),le=e=>(...r)=>{const t=e(...r),s=h(t);return!s||s&&t.$args_left<=0?se(t):le(t)},ue=n(((e,r)=>he(K(e),r-e))),fe=n(((e,r)=>e.filter(U(I)(r)))),he=n(((e,r)=>[...Array(r)].map(((r,t)=>e(t))))),me=n(((e,r)=>{for(const[t,s]of e)if(t(r))return s(r)})),ye=c(((e,r,t)=>({...t,[e]:r}))),de=c(((e,r,t)=>B((s=>{return ye(s,ee(e)<2?r:de(T(1,a,e),r,(o=t[s],l(o)||"object"!==i(o)?{}:t[s])),t);var o}),$)(e))),ge=n(((e,r)=>r.every(e))),be=n(((e,r)=>r.some(e))),we=n(((e,r)=>e.every((e=>e(r))))),je=n(((e,r)=>e.some((e=>e(r))))),Oe=n(((e,r)=>r[e])),qe=c(((e,r,t)=>D(t[e],r))),Ae=c(((e,r,t)=>D(r[e],t[e]))),Ee=c(((e,r,t)=>z(ee,(()=>Z(t)?e:B(z(Z,re(e),(t=>Ee(e,T(1,a,r),t))),U(Oe)(t),$)(r)),re(t),r))),Se=Ee(x),ke=c(((e,r,t)=>D(Se(e,t),r))),ve=c(((e,r,t)=>D(Se(e,r),Se(e,t)))),Pe=/^(.*?)(8|16|32|64)(Clamped)?Array$/,De=(e,r=!1)=>{const t=y(e);switch(t){case"Null":case"String":case"Number":case"Boolean":case"Symbol":return e;case"Array":return r?[...e]:Te(B(De,P(0)),e);case"Object":if(r)return{...e};const s={};for(let r in e)s[r]=De(e[r]);return s;default:return Pe.test(t)?e.constructor.from(e):e}},ze=c(((e,r,t)=>w(e,De(r),t))),Ne=n(((e,r)=>Ke(e,r))),Be=n(((e,r)=>{const t={};for(const s of e)s in r&&(t[s]=r[s]);return t})),_e=n(((e,r)=>Ke(((r,t)=>!I(t,e)),r))),Ce=n(((e,r)=>r.concat(e))),Ie=n(((e,r)=>r.join(e))),Te=n(((e,r)=>r.map(e))),Ue=n(((e,r)=>r.forEach(e))),$e=c(((e,r,t)=>r(t)&&e(t))),Fe=c(((e,r,t)=>t.replace(e,r))),Ke=n(((e,r)=>f(r)?r.filter(e):v(e,{...r}))),Le=n(((e,r)=>Object.assign({},e,r))),We=n(((e,r)=>O(De(e),De(r)))),Xe=n(((e,r)=>q(De(e),De(r)))),Ge=n(((e,r)=>A(De(e),De(r)))),He=c(((e,r,t)=>ye(e,r(t[e]),t))),Je=n(((e,r)=>S(e,Object.assign({},r)))),Me=n(((e,r)=>Te(((e,t)=>[e,r[t]]),e))),Qe=n(((e,r)=>ze(((e,t,s)=>ye(t,r[s],e)),{},e))),Re=c(((e,r,t)=>Te(((r,s)=>e(r,t[s])),r))),Ve=(()=>{const e=async(r,t,s)=>{s<t.length&&(await r(t[s]),await e(r,t,++s))};return n(((r,t)=>e(r,t,0)))})(),Ye=n((async(e,r)=>(await e(r),r))),Ze=n(((e,r)=>Promise.all(r.map(e)))),er=(()=>{const e=async(r,t,s)=>~s?await e(r,await r[s](t),--s):t;return(...r)=>t=>e(r,t,r.length-1)})(),rr=te,tr=te,sr=te,or=le,pr=ne,nr=be;exports.F=ae,exports.T=xe,exports.__=e,exports.add=K,exports.all=ge,exports.allPass=we,exports.always=re,exports.any=be,exports.anyPass=je,exports.append=ne,exports.assoc=ye,exports.assocPath=de,exports.bind=_,exports.both=$e,exports.callWith=ie,exports.clone=De,exports.cloneShallow=e=>De(e,!0),exports.complement=le,exports.compose=B,exports.composeAsync=er,exports.concat=Ce,exports.cond=me,exports.curry=o,exports.curry2=n,exports.curry3=c,exports.divide=Y,exports.echo=sr,exports.empty=e=>{switch(y(e)){case"String":return"";case"Object":return{};case"Array":return[];default:return x}},exports.equals=D,exports.explore=(e,r="log")=>pe((t=>console[r](e,t))),exports.filter=Ke,exports.find=Q,exports.findIndex=R,exports.flip=U,exports.forEach=Ue,exports.forEachAsync=Ze,exports.forEachSerial=Ve,exports.fromPairs=e=>Object.fromEntries(e),exports.genBy=he,exports.getTmpl=e=>{const r=[],t=[],s=e.length;let o,p,n,c=0,x=0,a=!1,i=$(e),l=!1;for(c=0;c<s;c++)switch(o=e[c],o){case"{":if(!i){a=!0,x=c;break}case"}":if(!i){a=!1,r.push(""),t.push(e.slice(x+1,c));break}default:n=e[c+1],l="\\"===o,a||l&&("{"===n||"}"===n)||(p=r.length-1,p<0&&(r.push(""),p++),r[p]+=o),i=l}return e=>{const s=[],o=r.length-1;for(const p in r)c=+p,s.push(r[c]),c!==o&&s.push(Se(t[c].split("."),e));return s.join("")}},exports.gt=X,exports.gte=H,exports.head=$,exports.identity=te,exports.ifElse=z,exports.includes=I,exports.indexOf=V,exports.intersection=fe,exports.isEmpty=e=>{switch(y(e)){case"String":case"Array":return 0==ee(e);case"Object":for(const r in e)return!1;return!0;default:return null}},exports.isNil=Z,exports.join=Ie,exports.keys=e=>Object.keys(e),exports.last=e=>e[ee(e)-1],exports.length=ee,exports.lt=G,exports.lte=J,exports.map=Te,exports.mapKeys=Je,exports.memoize=e=>{let r,t=!1;return()=>t?r:(t=!0,r=e())},exports.mergeDeep=We,exports.mergeDeepAdd=Ge,exports.mergeDeepX=Xe,exports.mergeShallow=Le,exports.mirror=rr,exports.multiply=W,exports.noop=(...e)=>{},exports.not=se,exports.notf=or,exports.nth=C,exports.omit=_e,exports.once=e=>{let r,t=!1;return(...s)=>t?r:(t=!0,r=e(...s))},exports.overProp=He,exports.path=Se,exports.pathEq=ke,exports.pathOr=Ee,exports.pathsEq=ve,exports.pick=Be,exports.pickBy=Ne,exports.prop=Oe,exports.propEq=qe,exports.propsEq=Ae,exports.push=pr,exports.qappend=g,exports.qassoc=b,exports.qfilter=v,exports.qmap=k,exports.qmapKeys=S,exports.qmergeDeep=O,exports.qmergeDeepAdd=A,exports.qmergeDeepX=q,exports.qmergeShallow=E,exports.qreduce=w,exports.range=ue,exports.reduce=ze,exports.reflect=tr,exports.replace=Fe,exports.reverse=e=>B((r=>ze(((t,s,o)=>g(e[r-o],t)),[],e)),K(-1),ee)(e),exports.sizeof=e=>{if("Object"===y(e)){let r=0;for(let t in e)r++;return r}return ee(e)},exports.slice=T,exports.some=nr,exports.sort=M,exports.split=ce,exports.subtract=L,exports.tail=F,exports.take=P,exports.tap=pe,exports.test=oe,exports.toLower=e=>e.toLowerCase(),exports.toPairs=e=>Object.entries(e),exports.toUpper=e=>e.toUpperCase(),exports.trim=e=>e.trim(),exports.type=y,exports.typeIs=d,exports.uncurry=e=>(...r)=>w(((e,r)=>e?e(r):e),e,r),exports.uniq=e=>w(((e,r)=>I(r,e)?e:g(r,e)),[],e),exports.values=e=>Object.values(e),exports.waitAll=e=>Promise.all(e),exports.waitTap=Ye,exports.when=N,exports.zip=Me,exports.zipObj=Qe,exports.zipWith=Re;
|
package/dist/bundle.d.ts
CHANGED
|
@@ -87,6 +87,54 @@ export declare const multiply: {
|
|
|
87
87
|
(a: number): (b: number) => number;
|
|
88
88
|
(a: number, b: number): number;
|
|
89
89
|
};
|
|
90
|
+
export declare const gt: {
|
|
91
|
+
(a: symbol, b: number): (a: number) => boolean;
|
|
92
|
+
(a: number, b: symbol): (b: number) => boolean;
|
|
93
|
+
(a: number): (b: number) => boolean;
|
|
94
|
+
(a: number, b: number): boolean;
|
|
95
|
+
};
|
|
96
|
+
export declare const lt: {
|
|
97
|
+
(a: symbol, b: number): (a: number) => boolean;
|
|
98
|
+
(a: number, b: symbol): (b: number) => boolean;
|
|
99
|
+
(a: number): (b: number) => boolean;
|
|
100
|
+
(a: number, b: number): boolean;
|
|
101
|
+
};
|
|
102
|
+
export declare const gte: {
|
|
103
|
+
(a: symbol, b: number): (a: number) => boolean;
|
|
104
|
+
(a: number, b: symbol): (b: number) => boolean;
|
|
105
|
+
(a: number): (b: number) => boolean;
|
|
106
|
+
(a: number, b: number): boolean;
|
|
107
|
+
};
|
|
108
|
+
export declare const lte: {
|
|
109
|
+
(a: symbol, b: number): (a: number) => boolean;
|
|
110
|
+
(a: number, b: symbol): (b: number) => boolean;
|
|
111
|
+
(a: number): (b: number) => boolean;
|
|
112
|
+
(a: number, b: number): boolean;
|
|
113
|
+
};
|
|
114
|
+
export declare const sort: {
|
|
115
|
+
(a: symbol, b: any[]): (a: any) => any[];
|
|
116
|
+
(a: any, b: symbol): (b: any[]) => any[];
|
|
117
|
+
(a: any): (b: any[]) => any[];
|
|
118
|
+
(a: any, b: any[]): any[];
|
|
119
|
+
};
|
|
120
|
+
export declare const find: {
|
|
121
|
+
(a: symbol, b: any[]): (a: Cond) => any;
|
|
122
|
+
(a: Cond, b: symbol): (b: any[]) => any;
|
|
123
|
+
(a: Cond): (b: any[]) => any;
|
|
124
|
+
(a: Cond, b: any[]): any;
|
|
125
|
+
};
|
|
126
|
+
export declare const findIndex: {
|
|
127
|
+
(a: symbol, b: any[]): (a: Cond) => number;
|
|
128
|
+
(a: Cond, b: symbol): (b: any[]) => number;
|
|
129
|
+
(a: Cond): (b: any[]) => number;
|
|
130
|
+
(a: Cond, b: any[]): number;
|
|
131
|
+
};
|
|
132
|
+
export declare const indexOf: {
|
|
133
|
+
(a: symbol, b: any[]): (a: any) => number;
|
|
134
|
+
(a: any, b: symbol): (b: any[]) => number;
|
|
135
|
+
(a: any): (b: any[]) => number;
|
|
136
|
+
(a: any, b: any[]): number;
|
|
137
|
+
};
|
|
90
138
|
export declare const divide: {
|
|
91
139
|
(a: symbol, b: number): (a: number) => number;
|
|
92
140
|
(a: number, b: symbol): (b: number) => number;
|
|
@@ -100,7 +148,6 @@ export declare const identity: (s: any) => any;
|
|
|
100
148
|
export declare const trim: (s: string) => string;
|
|
101
149
|
export declare const last: (s: any[] | string) => any;
|
|
102
150
|
export declare const not: (o: boolean) => boolean;
|
|
103
|
-
export declare const complement: (fn: AnyFunc) => (...args: any) => boolean | any;
|
|
104
151
|
export declare const keys: (o: AnyObject | any[]) => string[];
|
|
105
152
|
export declare const values: (o: AnyObject | any[]) => any[];
|
|
106
153
|
export declare const toPairs: (o: AnyObject | any[]) => [
|
|
@@ -140,6 +187,7 @@ export declare const callWith: {
|
|
|
140
187
|
(a: any[], b: AnyFunc<any, AnyArgs>): any;
|
|
141
188
|
};
|
|
142
189
|
export declare const noop: (..._args: any[]) => void;
|
|
190
|
+
export declare const complement: (fn: AnyFunc) => (...args: any) => boolean | any;
|
|
143
191
|
export declare const sizeof: (s: any[] | string | AnyObject) => number;
|
|
144
192
|
export declare const range: {
|
|
145
193
|
(a: symbol, b: number): (a: number) => any[];
|
|
@@ -162,54 +210,6 @@ export declare const genBy: {
|
|
|
162
210
|
};
|
|
163
211
|
export declare const once: <Func extends AnyFunc<any, AnyArgs>>(fn: Func) => (...args: Parameters<Func>) => any;
|
|
164
212
|
export declare const reverse: (xs: any[]) => any;
|
|
165
|
-
export declare const gt: {
|
|
166
|
-
(a: symbol, b: number): (a: number) => boolean;
|
|
167
|
-
(a: number, b: symbol): (b: number) => boolean;
|
|
168
|
-
(a: number): (b: number) => boolean;
|
|
169
|
-
(a: number, b: number): boolean;
|
|
170
|
-
};
|
|
171
|
-
export declare const lt: {
|
|
172
|
-
(a: symbol, b: number): (a: number) => boolean;
|
|
173
|
-
(a: number, b: symbol): (b: number) => boolean;
|
|
174
|
-
(a: number): (b: number) => boolean;
|
|
175
|
-
(a: number, b: number): boolean;
|
|
176
|
-
};
|
|
177
|
-
export declare const gte: {
|
|
178
|
-
(a: symbol, b: number): (a: number) => boolean;
|
|
179
|
-
(a: number, b: symbol): (b: number) => boolean;
|
|
180
|
-
(a: number): (b: number) => boolean;
|
|
181
|
-
(a: number, b: number): boolean;
|
|
182
|
-
};
|
|
183
|
-
export declare const lte: {
|
|
184
|
-
(a: symbol, b: number): (a: number) => boolean;
|
|
185
|
-
(a: number, b: symbol): (b: number) => boolean;
|
|
186
|
-
(a: number): (b: number) => boolean;
|
|
187
|
-
(a: number, b: number): boolean;
|
|
188
|
-
};
|
|
189
|
-
export declare const sort: {
|
|
190
|
-
(a: symbol, b: any[]): (a: any) => any[];
|
|
191
|
-
(a: any, b: symbol): (b: any[]) => any[];
|
|
192
|
-
(a: any): (b: any[]) => any[];
|
|
193
|
-
(a: any, b: any[]): any[];
|
|
194
|
-
};
|
|
195
|
-
export declare const find: {
|
|
196
|
-
(a: symbol, b: any[]): (a: Cond) => any;
|
|
197
|
-
(a: Cond, b: symbol): (b: any[]) => any;
|
|
198
|
-
(a: Cond): (b: any[]) => any;
|
|
199
|
-
(a: Cond, b: any[]): any;
|
|
200
|
-
};
|
|
201
|
-
export declare const findIndex: {
|
|
202
|
-
(a: symbol, b: any[]): (a: Cond) => number;
|
|
203
|
-
(a: Cond, b: symbol): (b: any[]) => number;
|
|
204
|
-
(a: Cond): (b: any[]) => number;
|
|
205
|
-
(a: Cond, b: any[]): number;
|
|
206
|
-
};
|
|
207
|
-
export declare const indexOf: {
|
|
208
|
-
(a: symbol, b: any[]): (a: any) => number;
|
|
209
|
-
(a: any, b: symbol): (b: any[]) => number;
|
|
210
|
-
(a: any): (b: any[]) => number;
|
|
211
|
-
(a: any, b: any[]): number;
|
|
212
|
-
};
|
|
213
213
|
export declare const explore: (caption: string, level?: string) => (b: any) => any;
|
|
214
214
|
export declare const cond: {
|
|
215
215
|
(a: symbol, b: any): (a: [
|
|
@@ -332,7 +332,12 @@ export declare const both: (...args: AnyArgs) => any;
|
|
|
332
332
|
export declare const isEmpty: (s: any) => boolean | null;
|
|
333
333
|
export declare const empty: (s: any) => {} | undefined;
|
|
334
334
|
export declare const replace: (...args: AnyArgs) => any;
|
|
335
|
-
export declare const filter:
|
|
335
|
+
export declare const filter: {
|
|
336
|
+
(a: symbol, b: any[] | AnyObject): (a: (v: any, k: string | number) => boolean) => any;
|
|
337
|
+
(a: (v: any, k: string | number) => boolean, b: symbol): (b: any[] | AnyObject) => any;
|
|
338
|
+
(a: (v: any, k: string | number) => boolean): (b: any[] | AnyObject) => any;
|
|
339
|
+
(a: (v: any, k: string | number) => boolean, b: any[] | AnyObject): any;
|
|
340
|
+
};
|
|
336
341
|
export declare const memoize: (fn: Function) => () => any;
|
|
337
342
|
export declare const mergeShallow: {
|
|
338
343
|
(a: symbol, b: AnyObject): (a: AnyObject) => AnyObject;
|
|
@@ -402,11 +407,16 @@ export declare const forEachSerial: {
|
|
|
402
407
|
};
|
|
403
408
|
/** Promise.all wrapper for functional pipelining. */
|
|
404
409
|
export declare const waitAll: (promises: Promise<any>[]) => Promise<any[]>;
|
|
410
|
+
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
411
|
+
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
412
|
+
* @param {T} s - any value to tap and return back
|
|
413
|
+
* @returns {T}
|
|
414
|
+
*/
|
|
405
415
|
export declare const waitTap: {
|
|
406
|
-
(a: symbol, b: any): (a:
|
|
407
|
-
(a:
|
|
408
|
-
(a:
|
|
409
|
-
(a:
|
|
416
|
+
(a: symbol, b: any): (a: AnyFunc<any, AnyArgs>) => Promise<any>;
|
|
417
|
+
(a: AnyFunc<any, AnyArgs>, b: symbol): (b: any) => Promise<any>;
|
|
418
|
+
(a: AnyFunc<any, AnyArgs>): (b: any) => Promise<any>;
|
|
419
|
+
(a: AnyFunc<any, AnyArgs>, b: any): Promise<any>;
|
|
410
420
|
};
|
|
411
421
|
/** Waits for all promises mapped by the fn. */
|
|
412
422
|
export declare const forEachAsync: {
|
|
@@ -477,13 +487,6 @@ export declare const qfilter: {
|
|
|
477
487
|
(a: (v: any, k: string | number) => boolean): (b: any[] | AnyObject) => any[] | AnyObject;
|
|
478
488
|
(a: (v: any, k: string | number) => boolean, b: any[] | AnyObject): any[] | AnyObject;
|
|
479
489
|
};
|
|
480
|
-
/** @deprecated */
|
|
481
|
-
export declare const qindexOf: {
|
|
482
|
-
(a: symbol, b: any[]): (a: any) => number;
|
|
483
|
-
(a: any, b: symbol): (b: any[]) => number;
|
|
484
|
-
(a: any): (b: any[]) => number;
|
|
485
|
-
(a: any, b: any[]): number;
|
|
486
|
-
};
|
|
487
490
|
export type StrTmpl = ((data: AnyObject) => string);
|
|
488
491
|
export declare const getTmpl: (tmpl: string) => StrTmpl;
|
|
489
492
|
|
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,u=0;for(;o&&u<n;u++)s[u]===e&&(s[u]=t[c-o],o--);for(u=n;o;u++,o--)s[u]=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),c=r=>function(t){return t===e?r:r(t)};function o(r){return function(t,n){const s=t===e,o=arguments.length;if(1===o&&s)throw new Error("Senseless placeholder usage.");return arguments.length>1?s?c((e=>r(e,n))):r(t,n):e=>r(t,e)}}function u(e){return s(e)}const a=void 0,i=1/0,l=e=>typeof e,f=e=>null===e,h=e=>"number"==l(e),b=e=>Array.isArray(e),g=e=>"function"===l(e),p={u:"U",b:"B",n:"N",s:"S",f:"F"},y=e=>e.toLowerCase(),
|
|
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,u=0;for(;o&&u<n;u++)s[u]===e&&(s[u]=t[c-o],o--);for(u=n;o;u++,o--)s[u]=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),c=r=>function(t){return t===e?r:r(t)};function o(r){return function(t,n){const s=t===e,o=arguments.length;if(1===o&&s)throw new Error("Senseless placeholder usage.");return arguments.length>1?s?c((e=>r(e,n))):r(t,n):e=>r(t,e)}}function u(e){return s(e)}const a=void 0,i=1/0,l=e=>typeof e,f=e=>null===e,h=e=>"number"==l(e),b=e=>Array.isArray(e),g=e=>"function"===l(e),p={u:"U",b:"B",n:"N",s:"S",f:"F"},y=e=>e.toLowerCase(),j=e=>e.toUpperCase(),d=e=>{const r=l(e);return"object"===r?f(e)?"Null":e.constructor.name:p[r[0]]+r.slice(1)},m=o(((e,r)=>d(r)===e)),w=o(((e,r)=>(r.push(e),r))),O=u(((e,r,t)=>(t[e]=r,t))),A=u(((e,r,t)=>t.reduce(e,r))),S=u(((e,r,t)=>{for(let n in t)switch(d(t[n])){case"Array":if(e>1&&"Array"===d(r[n]))switch(e){case 2:const s=r[n],c=t[n];for(const r in c)s[r]?S(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"===d(r[n])){S(e,r[n],t[n]);break}default:r[n]=t[n]}return r})),k=S(1),v=S(2),N=S(3),C=o(((e,r)=>Object.assign(e,r))),E=o(((e,r)=>{let t,n,s,c;for(t in e)n=e[t],[s,c]=g(n)?n(r):[n,r[t]],r[s]=c,t!==s&&delete r[t];return r})),P=o(((e,r)=>{for(let t in r)r[t]=e(r[t],+t,r);return r})),$=o(((e,r)=>{const t=b(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})),x=e=>(...r)=>A(((e,r)=>e?e(r):e),e,r),B=e=>(...r)=>r[e],U=o(((e,r)=>{const t=d(e);if(t===d(r)&&("Object"===t||"Array"==t)){if(f(e)||f(r))return e===r;if(e===r)return!0;for(const t of[e,r])for(const n in t)if(!(t===r&&n in e||t===e&&n in r&&U(e[n],r[n])))return!1;return!0}return e===r})),_=s(((e,r,t,n)=>e(n)?r(n):t(n))),F=u(((e,r,t)=>_(e,r,ce,t))),I=(...r)=>(...t)=>{let n,s=!0;for(let c=ne(r)-1;c>-1;c--)s?(s=!1,n=r[c](...t)):n=n===e?r[c]():r[c](n);return n},L=o(((e,r)=>e.bind(r))),q=o(((e,r)=>r[e])),z=o(((e,r)=>{if((e=>"string"===l(e))(r))return r.includes(e);for(const t of r)if(U(t,e))return!0;return!1})),D=u(((e,r,t)=>t.slice(e,h(r)?r:i))),G=e=>o(((r,t)=>e(t,r))),H=q(0),J=D(1,i),K=o(((e,r)=>e+r)),M=o(((e,r)=>r-e)),Q=o(((e,r)=>e*r)),R=o(((e,r)=>e>r)),T=o(((e,r)=>e<r)),V=o(((e,r)=>r>=e)),W=o(((e,r)=>r<=e)),X=o(((e,r)=>r.sort(e))),Y=o(((e,r)=>r.find(e))),Z=o(((e,r)=>r.findIndex(e))),ee=o(((e,r)=>Z(U(e),r))),re=o(((e,r)=>e/r)),te=e=>f(e)||(e=>e===a)(e),ne=e=>e.length,se=e=>()=>e,ce=e=>e,oe=e=>e.trim(),ue=e=>e[ne(e)-1],ae=e=>!e,ie=e=>Object.keys(e),le=e=>Object.values(e),fe=e=>Object.entries(e),he=o(((e,r)=>e.test(r))),be=o(((e,r)=>(e(r),r))),ge=o(((e,r)=>[...r,e])),pe=o(((e,r)=>r.split(e))),ye=se(!0),je=se(!1),de=o(((e,r)=>r(...e))),me=(...e)=>{},we=e=>(...r)=>{const t=e(...r),n=g(t);return!n||n&&t.$args_left<=0?ae(t):we(t)},Oe=e=>{if("Object"===d(e)){let r=0;for(let t in e)r++;return r}return ne(e)},Ae=o(((e,r)=>ve(K(e),r-e))),Se=e=>A(((e,r)=>z(r,e)?e:w(r,e)),[],e),ke=o(((e,r)=>e.filter(G(z)(r)))),ve=o(((e,r)=>[...Array(r)].map(((r,t)=>e(t))))),Ne=e=>{let r,t=!1;return(...n)=>t?r:(t=!0,r=e(...n))},Ce=e=>I((r=>Qe(((t,n,s)=>w(e[r-s],t)),[],e)),K(-1),ne)(e),Ee=(e,r="log")=>be((t=>console[r](e,t))),Pe=o(((e,r)=>{for(const[t,n]of e)if(t(r))return n(r)})),$e=u(((e,r,t)=>({...t,[e]:r}))),xe=u(((e,r,t)=>I((n=>{return $e(n,ne(e)<2?r:xe(D(1,i,e),r,(s=t[n],f(s)||"object"!==l(s)?{}:t[n])),t);var s}),H)(e))),Be=o(((e,r)=>r.every(e))),Ue=o(((e,r)=>r.some(e))),_e=o(((e,r)=>e.every((e=>e(r))))),Fe=o(((e,r)=>e.some((e=>e(r))))),Ie=o(((e,r)=>r[e])),Le=u(((e,r,t)=>U(t[e],r))),qe=u(((e,r,t)=>U(r[e],t[e]))),ze=u(((e,r,t)=>_(ne,(()=>te(t)?e:I(_(te,se(e),(t=>ze(e,D(1,i,r),t))),G(Ie)(t),H)(r)),se(t),r))),De=ze(a),Ge=u(((e,r,t)=>U(De(e,t),r))),He=u(((e,r,t)=>U(De(e,r),De(e,t)))),Je=/^(.*?)(8|16|32|64)(Clamped)?Array$/,Ke=(e,r=!1)=>{const t=d(e);switch(t){case"Null":case"String":case"Number":case"Boolean":case"Symbol":return e;case"Array":return r?[...e]:Ze(I(Ke,B(0)),e);case"Object":if(r)return{...e};const n={};for(let r in e)n[r]=Ke(e[r]);return n;default:return Je.test(t)?e.constructor.from(e):e}},Me=e=>Ke(e,!0),Qe=u(((e,r,t)=>A(e,Ke(r),t))),Re=o(((e,r)=>cr(e,r))),Te=o(((e,r)=>{const t={};for(const n of e)n in r&&(t[n]=r[n]);return t})),Ve=o(((e,r)=>cr(((r,t)=>!z(t,e)),r))),We=e=>Object.fromEntries(e),Xe=o(((e,r)=>r.concat(e))),Ye=o(((e,r)=>r.join(e))),Ze=o(((e,r)=>r.map(e))),er=o(((e,r)=>r.forEach(e))),rr=u(((e,r,t)=>r(t)&&e(t))),tr=e=>{switch(d(e)){case"String":case"Array":return 0==ne(e);case"Object":for(const r in e)return!1;return!0;default:return null}},nr=e=>{switch(d(e)){case"String":return"";case"Object":return{};case"Array":return[];default:return a}},sr=u(((e,r,t)=>t.replace(e,r))),cr=o(((e,r)=>b(r)?r.filter(e):$(e,{...r}))),or=e=>{let r,t=!1;return()=>t?r:(t=!0,r=e())},ur=o(((e,r)=>Object.assign({},e,r))),ar=o(((e,r)=>k(Ke(e),Ke(r)))),ir=o(((e,r)=>v(Ke(e),Ke(r)))),lr=o(((e,r)=>N(Ke(e),Ke(r)))),fr=u(((e,r,t)=>$e(e,r(t[e]),t))),hr=o(((e,r)=>E(e,Object.assign({},r)))),br=o(((e,r)=>Ze(((e,t)=>[e,r[t]]),e))),gr=o(((e,r)=>Qe(((e,t,n)=>$e(t,r[n],e)),{},e))),pr=u(((e,r,t)=>Ze(((r,n)=>e(r,t[n])),r))),yr=(()=>{const e=async(r,t,n)=>{n<t.length&&(await r(t[n]),await e(r,t,++n))};return o(((r,t)=>e(r,t,0)))})(),jr=e=>Promise.all(e),dr=o((async(e,r)=>(await e(r),r))),mr=o(((e,r)=>Promise.all(r.map(e)))),wr=(()=>{const e=async(r,t,n)=>~n?await e(r,await r[n](t),--n):t;return(...r)=>t=>e(r,t,r.length-1)})(),Or=ce,Ar=ce,Sr=ce,kr=we,vr=ge,Nr=Ue,Cr=e=>{const r=[],t=[],n=e.length;let s,c,o,u=0,a=0,i=!1,l=H(e),f=!1;for(u=0;u<n;u++)switch(s=e[u],s){case"{":if(!l){i=!0,a=u;break}case"}":if(!l){i=!1,r.push(""),t.push(e.slice(a+1,u));break}default:o=e[u+1],f="\\"===s,i||f&&("{"===o||"}"===o)||(c=r.length-1,c<0&&(r.push(""),c++),r[c]+=s),l=f}return e=>{const n=[],s=r.length-1;for(const c in r)u=+c,n.push(r[u]),u!==s&&n.push(De(t[u].split("."),e));return n.join("")}};export{je as F,ye as T,e as __,K as add,Be as all,_e as allPass,se as always,Ue as any,Fe as anyPass,ge as append,$e as assoc,xe as assocPath,L as bind,rr as both,de as callWith,Ke as clone,Me as cloneShallow,we as complement,I as compose,wr as composeAsync,Xe as concat,Pe as cond,s as curry,o as curry2,u as curry3,re as divide,Sr as echo,nr as empty,U as equals,Ee as explore,cr as filter,Y as find,Z as findIndex,G as flip,er as forEach,mr as forEachAsync,yr as forEachSerial,We as fromPairs,ve as genBy,Cr as getTmpl,R as gt,V as gte,H as head,ce as identity,_ as ifElse,z as includes,ee as indexOf,ke as intersection,tr as isEmpty,te as isNil,Ye as join,ie as keys,ue as last,ne as length,T as lt,W as lte,Ze as map,hr as mapKeys,or as memoize,ar as mergeDeep,lr as mergeDeepAdd,ir as mergeDeepX,ur as mergeShallow,Or as mirror,Q as multiply,me as noop,ae as not,kr as notf,q as nth,Ve as omit,Ne as once,fr as overProp,De as path,Ge as pathEq,ze as pathOr,He as pathsEq,Te as pick,Re as pickBy,Ie as prop,Le as propEq,qe as propsEq,vr as push,w as qappend,O as qassoc,$ as qfilter,P as qmap,E as qmapKeys,k as qmergeDeep,N as qmergeDeepAdd,v as qmergeDeepX,C as qmergeShallow,A as qreduce,Ae as range,Qe as reduce,Ar as reflect,sr as replace,Ce as reverse,Oe as sizeof,D as slice,Nr as some,X as sort,pe as split,M as subtract,J as tail,B as take,be as tap,he as test,y as toLower,fe as toPairs,j as toUpper,oe as trim,d as type,m as typeIs,x as uncurry,Se as uniq,le as values,jr as waitAll,dr as waitTap,F as when,br as zip,gr as zipObj,pr as zipWith};
|
package/package.json
CHANGED
package/src/quick.ts
CHANGED
|
@@ -13,32 +13,25 @@ export const qassoc = curry3(
|
|
|
13
13
|
}
|
|
14
14
|
)
|
|
15
15
|
export const qreduce = curry3(
|
|
16
|
-
<T>(fn: Reducer, accum: any, arr: T[]) =>
|
|
17
|
-
arr.reduce(fn, accum)
|
|
16
|
+
<T>(fn: Reducer, accum: any, arr: T[]) => arr.reduce(fn, accum)
|
|
18
17
|
)
|
|
19
18
|
// strategy is for arrays: 1->clean, 2->merge, 3->push.
|
|
20
19
|
const mergeDeep = curry3((strategy: 1|2|3, o1: AnyObject, o2: AnyObject): AnyObject => {
|
|
21
20
|
for(let k in o2) {
|
|
22
21
|
switch(type(o2[k])) {
|
|
23
22
|
case 'Array':
|
|
24
|
-
if(strategy>1 && type(o1[k])==='Array')
|
|
23
|
+
if(strategy>1 && type(o1[k])==='Array')
|
|
25
24
|
switch(strategy) {
|
|
26
25
|
case 2:
|
|
27
26
|
const o1k = o1[k], o2k = o2[k]
|
|
28
|
-
for(const i in o2k)
|
|
29
|
-
if(o1k[i])
|
|
30
|
-
|
|
31
|
-
} else {
|
|
32
|
-
o1k[i] = o2k[i]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
27
|
+
for(const i in o2k)
|
|
28
|
+
if(o1k[i]) mergeDeep(strategy, o1k[i], o2k[i])
|
|
29
|
+
else o1k[i] = o2k[i]
|
|
35
30
|
break
|
|
36
31
|
case 3: o1[k].push(...o2[k])
|
|
37
32
|
default: break
|
|
38
33
|
}
|
|
39
|
-
|
|
40
|
-
o1[k] = o2[k]
|
|
41
|
-
}
|
|
34
|
+
else o1[k] = o2[k]
|
|
42
35
|
break
|
|
43
36
|
case 'Object':
|
|
44
37
|
if(type(o1[k])==='Object') {
|
|
@@ -55,10 +48,7 @@ const mergeDeep = curry3((strategy: 1|2|3, o1: AnyObject, o2: AnyObject): AnyObj
|
|
|
55
48
|
export const qmergeDeep = mergeDeep(1)
|
|
56
49
|
export const qmergeDeepX = mergeDeep(2)
|
|
57
50
|
export const qmergeDeepAdd = mergeDeep(3)
|
|
58
|
-
export const qmergeShallow = curry2((o1: AnyObject, o2: AnyObject) =>
|
|
59
|
-
for(let k in o2) o1[k] = o2[k]
|
|
60
|
-
return o1
|
|
61
|
-
})
|
|
51
|
+
export const qmergeShallow = curry2((o1: AnyObject, o2: AnyObject) => Object.assign(o1, o2))
|
|
62
52
|
/** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
63
53
|
export const qmapKeys = curry2(
|
|
64
54
|
(
|
|
@@ -72,9 +62,7 @@ export const qmapKeys = curry2(
|
|
|
72
62
|
? (mapped as unknown as AnyFunc)(o)
|
|
73
63
|
: [mapped, o[k]]
|
|
74
64
|
o[newKey] = newValue
|
|
75
|
-
if(k !== newKey)
|
|
76
|
-
delete o[k]
|
|
77
|
-
}
|
|
65
|
+
if(k !== newKey) delete o[k]
|
|
78
66
|
}
|
|
79
67
|
return o
|
|
80
68
|
}
|
|
@@ -91,20 +79,19 @@ export const qfilter = curry2(
|
|
|
91
79
|
data: any[] | AnyObject
|
|
92
80
|
) => {
|
|
93
81
|
const isArr = isArray(data)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} else {
|
|
99
|
-
// TODO: handle Maps and Sets ?
|
|
100
|
-
delete data[k]
|
|
101
|
-
}
|
|
102
|
-
}
|
|
82
|
+
let indicies_offset: number, indicies2rm: number[]
|
|
83
|
+
if(isArr) {
|
|
84
|
+
indicies_offset = 0
|
|
85
|
+
indicies2rm = []
|
|
103
86
|
}
|
|
87
|
+
for(let k in data)
|
|
88
|
+
if(!cond(data[k], k)) // @ts-ignore
|
|
89
|
+
if(isArr) indicies2rm.push(+k)
|
|
90
|
+
else
|
|
91
|
+
delete data[k]
|
|
92
|
+
if(isArr)// @ts-ignore
|
|
93
|
+
for(const i of indicies2rm) // @ts-ignore
|
|
94
|
+
data.splice(i - indicies_offset++, 1)
|
|
104
95
|
return data
|
|
105
96
|
}
|
|
106
|
-
)
|
|
107
|
-
/** @deprecated */
|
|
108
|
-
export const qindexOf = curry2(
|
|
109
|
-
(x: any, xs: any[]) => xs.indexOf(x)
|
|
110
97
|
)
|
package/src/safe.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __, curry, curry2, curry3 } from './curry'
|
|
2
2
|
import { isNum, isUndef, undef, isNull, isArray, isFunc, isStr, isObj, inf } from './utils'
|
|
3
|
-
import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd } from './quick'
|
|
3
|
+
import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd, qfilter } from './quick'
|
|
4
4
|
import { AnyFunc, Cond, AnyObject, Reducer } from './types'
|
|
5
5
|
import { type } from './common'
|
|
6
6
|
// over, lensProp
|
|
@@ -9,22 +9,14 @@ export const take = (argN: number) => (...args: any[]) => args[argN]
|
|
|
9
9
|
export const equals = curry2((a: any, b: any) => {
|
|
10
10
|
const typea = type(a)
|
|
11
11
|
if(typea===type(b) && (typea==='Object' || typea=='Array')) {
|
|
12
|
-
if(isNull(a) || isNull(b))
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return true
|
|
17
|
-
}
|
|
18
|
-
for(const v of [a, b]) {
|
|
19
|
-
for(const k in v) {
|
|
12
|
+
if(isNull(a) || isNull(b)) return a===b
|
|
13
|
+
if(a===b) return true
|
|
14
|
+
for(const v of [a, b])
|
|
15
|
+
for(const k in v)
|
|
20
16
|
if(
|
|
21
17
|
!((v===b) && (k in a)) &&
|
|
22
18
|
!((v===a) && (k in b) && equals(a[k], b[k]))
|
|
23
|
-
)
|
|
24
|
-
return false
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
19
|
+
) return false
|
|
28
20
|
return true
|
|
29
21
|
}
|
|
30
22
|
return a===b
|
|
@@ -60,14 +52,10 @@ export const compose = (
|
|
|
60
52
|
return s as any as TOut
|
|
61
53
|
}
|
|
62
54
|
)
|
|
63
|
-
|
|
64
55
|
export const bind = curry2<AnyFunc>(
|
|
65
56
|
(fn: AnyFunc, context: any) => fn.bind(context)
|
|
66
57
|
)
|
|
67
|
-
|
|
68
|
-
const _nth = <T=any>(i: number, data: T[] | string) => data[i]
|
|
69
|
-
export const nth = curry2(_nth)
|
|
70
|
-
|
|
58
|
+
export const nth = curry2(<T=any>(i: number, data: T[] | string) => data[i])
|
|
71
59
|
export const includes = curry2(
|
|
72
60
|
<T>(s: T, ss: T[]) => {
|
|
73
61
|
if(isStr(ss)) return ss.includes(s)
|
|
@@ -81,15 +69,22 @@ export const slice = curry3(
|
|
|
81
69
|
(from: number, to: number, o: any[] | string) =>
|
|
82
70
|
o.slice(from, (isNum(to)?to:inf) as number)
|
|
83
71
|
)
|
|
84
|
-
export const flip =
|
|
85
|
-
<T
|
|
86
|
-
|
|
87
|
-
)
|
|
72
|
+
export const flip = <T extends AnyFunc>(fn: T) => curry2(
|
|
73
|
+
(b: Parameters<T>[1], a: Parameters<T>[0]) => fn(a, b)
|
|
74
|
+
)
|
|
88
75
|
export const head = nth(0) as <T = any>(xs: T[] | string) => T
|
|
89
|
-
export const tail = slice(1, inf)
|
|
76
|
+
export const tail = slice(1, inf)
|
|
90
77
|
export const add = curry2((n: number, m: number) => n+m)
|
|
91
78
|
export const subtract = curry2((n: number, m: number) => m-n)
|
|
92
79
|
export const multiply = curry2((n: number, m: number) => n*m)
|
|
80
|
+
export const gt = curry2( (a: number, b: number) => a>b )
|
|
81
|
+
export const lt = curry2( (a: number, b: number) => a<b )
|
|
82
|
+
export const gte = curry2( (a: number, b: number) => b>=a )
|
|
83
|
+
export const lte = curry2( (a: number, b: number) => b<=a )
|
|
84
|
+
export const sort = curry2((sortFn: any, xs: any[]) => xs.sort(sortFn))
|
|
85
|
+
export const find = curry2((fn: Cond, s: any[]) => s.find(fn))
|
|
86
|
+
export const findIndex = curry2((fn: Cond, s: any[]) => s.findIndex(fn))
|
|
87
|
+
export const indexOf = curry2((x: any, xs: any[]) => findIndex(equals(x), xs))
|
|
93
88
|
export const divide = curry2((n: number, m: number) => n/m)
|
|
94
89
|
export const isNil = (s: any) => isNull(s) || isUndef(s)
|
|
95
90
|
export const length = (s: any[] | string) => s.length
|
|
@@ -98,11 +93,6 @@ export const identity = (s: any) => s
|
|
|
98
93
|
export const trim = (s: string) => s.trim()
|
|
99
94
|
export const last = (s: any[] | string) => s[length(s)-1]
|
|
100
95
|
export const not = (o: boolean) => !o
|
|
101
|
-
export const complement = (fn: AnyFunc) => (...args: any) => {
|
|
102
|
-
const out = fn(...args)
|
|
103
|
-
const f = isFunc(out)
|
|
104
|
-
return !f || f&&out.$args_left<=0 ? not(out) : complement(out)
|
|
105
|
-
}
|
|
106
96
|
export const keys = (o: AnyObject | any[]) => Object.keys(o)
|
|
107
97
|
export const values = (o: AnyObject | any[]) => Object.values(o)
|
|
108
98
|
export const toPairs = (o: AnyObject | any[]) => Object.entries(o)
|
|
@@ -114,6 +104,11 @@ export const T = always<true>(true) as (...args: any[]) => true
|
|
|
114
104
|
export const F = always<false>(false) as (...args: any[]) => false
|
|
115
105
|
export const callWith = curry2((args: any[], fn: AnyFunc) => fn(...args))
|
|
116
106
|
export const noop = (..._args: any[]) => {}
|
|
107
|
+
export const complement = (fn: AnyFunc) => (...args: any) => {
|
|
108
|
+
const out = fn(...args)
|
|
109
|
+
const f = isFunc(out)
|
|
110
|
+
return !f || f&&out.$args_left<=0 ? not(out) : complement(out)
|
|
111
|
+
}
|
|
117
112
|
export const sizeof = (s: any[] | string | AnyObject) => {
|
|
118
113
|
if(type(s) === 'Object') {
|
|
119
114
|
let len = 0
|
|
@@ -156,14 +151,6 @@ export const reverse = (xs: any[]) => compose(
|
|
|
156
151
|
add(-1),
|
|
157
152
|
length
|
|
158
153
|
)(xs)
|
|
159
|
-
export const gt = curry2( (a: number, b: number) => a>b )
|
|
160
|
-
export const lt = curry2( (a: number, b: number) => a<b )
|
|
161
|
-
export const gte = curry2( (a: number, b: number) => b>=a )
|
|
162
|
-
export const lte = curry2( (a: number, b: number) => b<=a )
|
|
163
|
-
export const sort = curry2((sortFn: any, xs: any[]) => xs.sort(sortFn))
|
|
164
|
-
export const find = curry2((fn: Cond, s: any[]) => s.find(fn))
|
|
165
|
-
export const findIndex = curry2((fn: Cond, s: any[]) => s.findIndex(fn))
|
|
166
|
-
export const indexOf = curry2((x: any, xs: any[]) => findIndex(equals(x), xs))
|
|
167
154
|
export const explore = (caption: string, level = 'log') => tap(
|
|
168
155
|
(v: any) => console[level](caption, v)
|
|
169
156
|
)
|
|
@@ -247,9 +234,7 @@ export const clone = (s: any, shallow = false) => {
|
|
|
247
234
|
case 'Object':
|
|
248
235
|
if(shallow) return {...s}
|
|
249
236
|
const out = {}
|
|
250
|
-
for(let k in s)
|
|
251
|
-
out[k] = clone(s[k])
|
|
252
|
-
}
|
|
237
|
+
for(let k in s) out[k] = clone(s[k])
|
|
253
238
|
return out
|
|
254
239
|
case 'String': case 'Number':
|
|
255
240
|
case 'Boolean': case 'Symbol':
|
|
@@ -275,11 +260,8 @@ export const pickBy = curry2(
|
|
|
275
260
|
export const pick = curry2(
|
|
276
261
|
(props: string[], o: AnyObject) => {
|
|
277
262
|
const out = {}
|
|
278
|
-
for(const p of props)
|
|
279
|
-
if(p in o)
|
|
280
|
-
out[p] = o[p]
|
|
281
|
-
}
|
|
282
|
-
}
|
|
263
|
+
for(const p of props)
|
|
264
|
+
if(p in o) out[p] = o[p]
|
|
283
265
|
return out
|
|
284
266
|
}
|
|
285
267
|
)
|
|
@@ -329,7 +311,7 @@ export const replace = curry3(
|
|
|
329
311
|
a: string | RegExp,
|
|
330
312
|
b: string | ((substring: string, ...ps: any[]) => string),
|
|
331
313
|
where: string
|
|
332
|
-
// @ts-ignore
|
|
314
|
+
// @ts-ignore Some bug with overload.
|
|
333
315
|
) => where.replace(a, b)
|
|
334
316
|
)
|
|
335
317
|
export const filter = curry2(
|
|
@@ -338,11 +320,7 @@ export const filter = curry2(
|
|
|
338
320
|
data: any[] | AnyObject
|
|
339
321
|
) => isArray(data)
|
|
340
322
|
? data.filter(cond)
|
|
341
|
-
:
|
|
342
|
-
fromPairs,
|
|
343
|
-
filter(([k, v]) => cond(v, k)),
|
|
344
|
-
toPairs
|
|
345
|
-
)(data)
|
|
323
|
+
: qfilter(cond, {...data})
|
|
346
324
|
)
|
|
347
325
|
export const memoize = (fn: Function) => {
|
|
348
326
|
let cache: any
|
|
@@ -408,7 +386,12 @@ export const forEachSerial = (() => {
|
|
|
408
386
|
})()
|
|
409
387
|
/** Promise.all wrapper for functional pipelining. */
|
|
410
388
|
export const waitAll = (promises: Promise<any>[]) => Promise.all(promises)
|
|
411
|
-
|
|
389
|
+
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
390
|
+
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
391
|
+
* @param {T} s - any value to tap and return back
|
|
392
|
+
* @returns {T}
|
|
393
|
+
*/
|
|
394
|
+
export const waitTap = curry2(async (fn: AnyFunc, s: any) => { await fn(s); return s })
|
|
412
395
|
/** Waits for all promises mapped by the fn. */
|
|
413
396
|
export const forEachAsync = curry2(
|
|
414
397
|
(fn: (item: any) => Promise<any>, items: any[]) =>
|
|
@@ -420,7 +403,7 @@ export const composeAsync = (() => {
|
|
|
420
403
|
~i ? await pipe(fns, await fns[i](data), --i) : data
|
|
421
404
|
return <T = any>(...fns: AnyFunc[]) =>
|
|
422
405
|
(data?: any) => pipe(fns, data, fns.length-1) as Promise<T>
|
|
423
|
-
})()
|
|
406
|
+
})()
|
|
424
407
|
|
|
425
408
|
// ALIASES
|
|
426
409
|
export const mirror = identity
|