@design-edito/tools 0.0.31 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ function e(n,r){return typeof r=="string"?n===r:n.match(r)!==null}function g(n,r){return Array.isArray(r)?r.some(t=>e(n,t)):e(n,r)}function i(n,r){return Array.isArray(r)?r.every(t=>e(n,t)):e(n,r)}export{e as a,g as b,i as c};
package/index.js CHANGED
@@ -33,6 +33,8 @@ import * as roundNumbers from './utils/agnostic/round-numbers/index.js'
33
33
  import * as selectorToElement from './utils/agnostic/selector-to-element/index.js'
34
34
  import * as silentLog from './utils/agnostic/silent-log/index.js'
35
35
  import * as strToNodes from './utils/agnostic/str-to-nodes/index.js'
36
+ import * as stringMatches from './utils/agnostic/string-matches/index.js'
37
+ import * as stringNormalizeIndent from './utils/agnostic/string-normalize-indent/index.js'
36
38
  import * as throttleDebounce from './utils/agnostic/throttle-debounce/index.js'
37
39
  import * as toAlphanum from './utils/agnostic/to-alphanum/index.js'
38
40
  import * as transition from './utils/agnostic/transition/index.js'
@@ -79,6 +81,8 @@ export { roundNumbers }
79
81
  export { selectorToElement }
80
82
  export { silentLog }
81
83
  export { strToNodes }
84
+ export { stringMatches }
85
+ export { stringNormalizeIndent }
82
86
  export { throttleDebounce }
83
87
  export { toAlphanum }
84
88
  export { transition }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design-edito/tools",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "description": "",
5
5
  "author": "Maxime Fabas",
6
6
  "license": "ISC",
@@ -1 +1 @@
1
- export default function isInEnum<E extends Object>(enumObj: E, value: unknown): value is E[keyof E];
1
+ export default function isInEnum<E extends Record<string, string | number>>(enumObj: E, value: string | number): value is E[keyof E];
@@ -1 +1 @@
1
- function u(e,n){return Object.values(e).includes(n)}export{u as default};
1
+ function l(s,n){let t=Object.keys(s),c=Object.values(s).filter(e=>typeof e=="number");return t.filter(e=>!c.includes(parseInt(e,10))).map(e=>s[e]).includes(n)}export{l as default};
@@ -1,6 +1,11 @@
1
- type FuncRecord = Record<string, (...args: any[]) => any>;
2
- type UnwrapPromise<PromiseOrNot> = PromiseOrNot extends Promise<infer Resolved> ? Resolved : PromiseOrNot;
3
- export default function recordFormat<Format extends FuncRecord>(input: Record<string, unknown>, format: Format): Promise<{
4
- [Key in keyof Format]: UnwrapPromise<ReturnType<Format[Key]>>;
5
- }>;
6
- export {};
1
+ export type FormatKey<Input extends {} = any> = keyof Input | string;
2
+ export type InputValue<Input extends {}, Key extends FormatKey<Input>> = Input extends Record<Key, infer V> ? V : undefined;
3
+ export type FormatterFunc<I, O> = (val: I) => O | Promise<O>;
4
+ export type Format<Input extends {} = any> = {
5
+ [Key in FormatKey<Input>]: FormatterFunc<InputValue<Input, Key>, any>;
6
+ };
7
+ export type UnwrapPromise<PromiseOrNot> = PromiseOrNot extends Promise<infer Resolved> ? Resolved : PromiseOrNot;
8
+ export type Formatted<F extends Format<{}>> = {
9
+ [Key in keyof F]: UnwrapPromise<ReturnType<F[Key]>>;
10
+ };
11
+ export default function recordFormat<I extends {}, F extends Format<I>>(input: I, format: F): Promise<Formatted<F>>;
@@ -1 +1 @@
1
- async function y(n,s){let e={},r=[];return Object.entries(s).forEach(async([o,a])=>{let i=n[o],t=a(i);r.push(t);let m=await t;e[o]=m}),await Promise.all(r),e}export{y as default};
1
+ async function a(o,n){let t={};for(let e in n){let r=n[e];typeof r=="function"?t[e]=await r(o[e]):t[e]=r}return t}export{a as default};
@@ -0,0 +1,4 @@
1
+ export default function stringMatches(input: string, matcher: string | RegExp): boolean;
2
+ export { stringMatches };
3
+ export declare function stringMatchesSome(input: string, matchers: string | RegExp | Array<string | RegExp>): boolean;
4
+ export declare function stringMatchesEvery(input: string, matchers: string | RegExp | Array<string | RegExp>): boolean;
@@ -0,0 +1 @@
1
+ import{a,b,c}from"../../../chunks/chunk-KNE7WIIW.js";export{a as default,a as stringMatches,c as stringMatchesEvery,b as stringMatchesSome};
@@ -0,0 +1 @@
1
+ export default function stringNormalizeIndent(input: string, indentLevel?: number): string;
@@ -0,0 +1,3 @@
1
+ function r(i,t=0){let s=" ".repeat(t);return i.split(`
2
+ `).map(e=>e.replace(/^\s*/igm,"")).map(e=>{let n=e.match(/^\|+/igm)?.[0].length??0,p=e.slice(n);return" ".repeat(n)+p}).map(e=>s+e).join(`
3
+ `)}export{r as default};
@@ -15,8 +15,8 @@ export type Options = {
15
15
  dedupeSimlinksContents?: boolean;
16
16
  maxDepth?: number;
17
17
  returnRelative?: boolean;
18
- exclude?: RegExp | null;
19
- include?: RegExp | null;
18
+ exclude?: RegExp | string | (RegExp | string)[] | null;
19
+ include?: RegExp | string | (RegExp | string)[] | null;
20
20
  filter?: ((path: string, details: ChildDetails) => boolean | Promise<boolean>);
21
21
  };
22
22
  export declare const defaultOptions: Required<Options>;
@@ -1 +1 @@
1
- import{promises as a}from"node:fs";import h from"node:path";var P={directories:!0,files:!0,symlinks:!0,hidden:!0,followSimlinks:!1,dedupeSimlinksContents:!1,maxDepth:1/0,returnRelative:!1,exclude:null,include:null,filter:()=>!0},w=s=>({...P,...s}),v={depth:0,lstats:null,rootPath:null},g=s=>({...v,...s});async function O(...s){let[u,c]=s,t=w(c??{}),e=await p(...s);return t.returnRelative?e.map(i=>h.relative(u,i)):e}async function p(s,u={},c={}){let t=w(u),e=g(c);e.rootPath===null&&(e.rootPath=s);let i=[];if(e.depth>t.maxDepth)return i;try{if(!(e.lstats??await a.lstat(s)).isDirectory())return i}catch{return i}let S=await a.readdir(s);return await Promise.all(S.map(async d=>{let o=h.join(s,d),k=h.relative(e.rootPath??s,o),r=await a.lstat(o);try{let l=r.isDirectory(),n=r.isSymbolicLink(),f=!l&&!n,x=h.basename(o).startsWith("."),C=l?"directory":n?"symlink":"file";if(l&&t.directories===!1)throw!0;if(n&&t.symlinks===!1||f&&t.files===!1||x&&t.hidden===!1)throw!1;let m=n?await a.realpath(o):o,y=t.returnRelative?k:o,R=t.exclude?.test(y)===!0,D=t.include?.test(y)===!0;if(R&&!D)throw!1;if(!await t.filter(y,{type:C,hidden:x,realPath:m}))throw!0;if(n)if(t.followSimlinks===!1)i.push(o);else{let b=await p(m,t,{...e,depth:e.depth+1});i.push(m,...b)}else if(l){let b=await p(o,t,{...e,depth:e.depth+1,lstats:r});i.push(o,...b)}else i.push(o)}catch(l){if(typeof l!="boolean")throw new Error("This try/catch block should only throw booleans");if(!l)return[];let f=await p(o,t,{...e,depth:e.depth+1,lstats:r});i.push(...f)}})),t.dedupeSimlinksContents?Array.from(new Set(i)):i}export{O as default,v as defaultContext,P as defaultOptions,g as fillContext,w as fillOptions};
1
+ import{b as x}from"../../../chunks/chunk-KNE7WIIW.js";import{promises as a}from"node:fs";import h from"node:path";var P={directories:!0,files:!0,symlinks:!0,hidden:!0,followSimlinks:!1,dedupeSimlinksContents:!1,maxDepth:1/0,returnRelative:!1,exclude:null,include:null,filter:()=>!0},S=s=>({...P,...s}),v={depth:0,lstats:null,rootPath:null},O=s=>({...v,...s});async function E(...s){let[c,u]=s,t=S(u??{}),e=await p(...s);return t.returnRelative?e.map(i=>h.relative(c,i)):e}async function p(s,c={},u={}){let t=S(c),e=O(u);e.rootPath===null&&(e.rootPath=s);let i=[];if(e.depth>t.maxDepth)return i;try{if(!(e.lstats??await a.lstat(s)).isDirectory())return i}catch{return i}let k=await a.readdir(s);return await Promise.all(k.map(async d=>{let o=h.join(s,d),R=h.relative(e.rootPath??s,o),r=await a.lstat(o);try{let n=r.isDirectory(),l=r.isSymbolicLink(),f=!n&&!l,w=h.basename(o).startsWith("."),g=n?"directory":l?"symlink":"file";if(n&&t.directories===!1)throw!0;if(l&&t.symlinks===!1||f&&t.files===!1||w&&t.hidden===!1)throw!1;let m=l?await a.realpath(o):o,y=t.returnRelative?R:o,C=x(y,t.exclude??[]),D=x(y,t.include??[]);if(C&&!D)throw!1;if(!await t.filter(y,{type:g,hidden:w,realPath:m}))throw!0;if(l)if(t.followSimlinks===!1)i.push(o);else{let b=await p(m,t,{...e,depth:e.depth+1});i.push(m,...b)}else if(n){let b=await p(o,t,{...e,depth:e.depth+1,lstats:r});i.push(o,...b)}else i.push(o)}catch(n){if(typeof n!="boolean")throw new Error("This try/catch block should only throw booleans");if(!n)return[];let f=await p(o,t,{...e,depth:e.depth+1,lstats:r});i.push(...f)}})),t.dedupeSimlinksContents?Array.from(new Set(i)):i}export{E as default,v as defaultContext,P as defaultOptions,O as fillContext,S as fillOptions};