@mxfb/tools 0.0.36 → 0.0.38

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.
@@ -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
@@ -1,4 +1,5 @@
1
1
  import * as Comp from './components/Comp/index.js'
2
+ import * as wipTennis from './utils/agnostic/_WIP_tennis/index.js'
2
3
  import * as absoluteModulo from './utils/agnostic/absolute-modulo/index.js'
3
4
  import * as array from './utils/agnostic/array/index.js'
4
5
  import * as assert from './utils/agnostic/assert/index.js'
@@ -33,6 +34,8 @@ import * as roundNumbers from './utils/agnostic/round-numbers/index.js'
33
34
  import * as selectorToElement from './utils/agnostic/selector-to-element/index.js'
34
35
  import * as silentLog from './utils/agnostic/silent-log/index.js'
35
36
  import * as strToNodes from './utils/agnostic/str-to-nodes/index.js'
37
+ import * as stringMatches from './utils/agnostic/string-matches/index.js'
38
+ import * as stringNormalizeIndent from './utils/agnostic/string-normalize-indent/index.js'
36
39
  import * as throttleDebounce from './utils/agnostic/throttle-debounce/index.js'
37
40
  import * as toAlphanum from './utils/agnostic/to-alphanum/index.js'
38
41
  import * as transition from './utils/agnostic/transition/index.js'
@@ -42,9 +45,11 @@ import * as getCurrentDownlink from './utils/browser/get-current-downlink/index.
42
45
  import * as getNodeAncestors from './utils/browser/get-node-ancestors/index.js'
43
46
  import * as isInDirectory from './utils/node/is-in-directory/index.js'
44
47
  import * as listSubpaths from './utils/node/list-subpaths/index.js'
48
+ import * as mxfbCliConfig from './utils/node/mxfb-cli-config/index.js'
45
49
  import * as processExit from './utils/node/process-exit/index.js'
46
50
  import * as readWriteFile from './utils/node/read-write-file/index.js'
47
51
  export { Comp }
52
+ export { wipTennis }
48
53
  export { absoluteModulo }
49
54
  export { array }
50
55
  export { assert }
@@ -79,6 +84,8 @@ export { roundNumbers }
79
84
  export { selectorToElement }
80
85
  export { silentLog }
81
86
  export { strToNodes }
87
+ export { stringMatches }
88
+ export { stringNormalizeIndent }
82
89
  export { throttleDebounce }
83
90
  export { toAlphanum }
84
91
  export { transition }
@@ -88,5 +95,6 @@ export { getCurrentDownlink }
88
95
  export { getNodeAncestors }
89
96
  export { isInDirectory }
90
97
  export { listSubpaths }
98
+ export { mxfbCliConfig }
91
99
  export { processExit }
92
100
  export { readWriteFile }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mxfb/tools",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "description": "",
5
5
  "author": "Maxime Fabas",
6
6
  "license": "ISC",
@@ -0,0 +1,2 @@
1
+ export declare namespace Tennis {
2
+ }
@@ -0,0 +1 @@
1
+ var i;(f=>{function s(S){let _=[0,0];return S.forEach(e=>{if(_.includes(5))return;let r=e?0:1,t=e?1:0,n=_[r],o=_[t];if(!(o===5||n===5)){if(o===4&&n===3){_[t]=3;return}if(o===3&&n===4){_[r]=5;return}if(n===3){_[r]=5;return}_[r]++}}),_}function a(S){let[_,e]=S;return _===5?!0:e===5?!1:null}function d(S){let _=[0,0],e=!1;return S.forEach(r=>{if(e||_.includes(7))return;let[t,n]=_;if(t>=6&&n<5||n<=6&&t<5)return;let o=s(r),c=a(o);if(c===!0){_[0]++;return}if(c===!1){_[1]++;return}e=!0}),_}})(i||={});export{i as Tennis};
@@ -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};
@@ -0,0 +1,19 @@
1
+ export type Config = {
2
+ mxfb_projects_sync?: {
3
+ lm_path?: string;
4
+ mxfb_path?: string;
5
+ };
6
+ };
7
+ export declare const emptyConfigObj: Config;
8
+ export declare function createConfigFile(force?: boolean): Promise<true | Error>;
9
+ declare const deletionSecurityPhrase = "THIS IS A DESTRUCTIVE AND DEFINITIVE ACTION";
10
+ export declare function deleteConfigDir(security: typeof deletionSecurityPhrase): Promise<true | Error>;
11
+ export declare function deleteConfigFile(security: typeof deletionSecurityPhrase): Promise<true | Error>;
12
+ export declare function ensureConfigFile(): Promise<true | Error>;
13
+ export declare function getConfigFile(): Promise<string | Error>;
14
+ export declare function validateConfigObj(configObj: any): configObj is Config;
15
+ export declare function parseConfigFile(fileContents: string): Config | Error;
16
+ export declare function getConfig(create?: boolean): Promise<Config | Error>;
17
+ export type ConfigUpdater = Partial<Config> | ((curr: Config) => Config);
18
+ export declare function updateConfig(updater: ConfigUpdater, create?: boolean): Promise<true | Error>;
19
+ export {};
@@ -0,0 +1,2 @@
1
+ import u from"node:os";import{promises as n}from"node:fs";import a from"node:path";var g=u.homedir(),f=a.join(g,".config/mxfb-cli"),o=a.join(f,"config.json"),p={};async function y(t=!1){await n.mkdir(f,{recursive:!0});try{if(await n.stat(o),t===!0)throw"create anyway";return!0}catch{try{return await n.writeFile(o,`${JSON.stringify(p,null,2)}
2
+ `,{encoding:"utf-8"}),!0}catch(e){return e instanceof Error?e:typeof e=="string"?new Error(e):new Error(`${e}`)}}}var s="THIS IS A DESTRUCTIVE AND DEFINITIVE ACTION";async function P(t){return t!==s?new Error("You must provide the security phrase"):(await n.rm(f,{recursive:!0,force:!0}),!0)}async function b(t){return t!==s?new Error("You must provide the security phrase"):(await n.rm(f),!0)}async function l(){try{return await n.stat(o),!0}catch{try{let r=await y();if(r instanceof Error)throw r;return!0}catch(r){return r instanceof Error?r:typeof r=="string"?new Error(r):new Error(`${r}`)}}}async function E(){try{return await n.readFile(o,{encoding:"utf-8"})}catch(t){return t instanceof Error?t:typeof t=="string"?new Error(t):new Error(`${t}`)}}function w(t){return!0}function m(t){try{let r=JSON.parse(t);if(!w(r))throw new Error(`Invalid config file shape: ${t}`);return r}catch(r){return r instanceof Error?r:typeof r=="string"?new Error(r):new Error(`${r}`)}}async function C(t=!1){if(t){let i=await l();if(i!==!0)return i}let r=await E();if(r instanceof Error)return r;let e=m(r);return e instanceof Error,e}async function F(t,r=!1){let e=await C(r);if(e instanceof Error)return e;let i=typeof t=="function"?t(e):{...e,...t},c=JSON.stringify(i,null,2);return await n.writeFile(o,c,{encoding:"utf-8"}),!0}export{y as createConfigFile,P as deleteConfigDir,b as deleteConfigFile,p as emptyConfigObj,l as ensureConfigFile,C as getConfig,E as getConfigFile,m as parseConfigFile,F as updateConfig,w as validateConfigObj};