@willbooster/shared-lib 1.8.1 → 2.0.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.
@@ -1,2 +1,2 @@
1
- "use strict";var r=require("node:child_process");exports.ignoreEnoent=function(r){try{return r()}catch(r){if("object"==typeof r&&r&&"code"in r&&"ENOENT"===r.code)return;throw r}},exports.ignoreEnoentAsync=async function(r){try{return await r()}catch(r){if("object"==typeof r&&r&&"code"in r&&"ENOENT"===r.code)return;throw r}},exports.ignoreError=function(r){try{return r()}catch(r){}},exports.ignoreErrorAsync=async function(r){try{return await r()}catch(r){}},exports.shuffle=function(r){for(let t=r.length-1;t>0;t--){const n=Math.floor(Math.random()*(t+1));[r[t],r[n]]=[r[n],r[t]]}return r},exports.spawnAsync=async function(t,n,o){return new Promise(((e,c)=>{try{var s,i;const a=r.spawn(t,null!=n?n:[],null!=o?o:{});let u="",d="";null===(s=a.stdout)||void 0===s||s.on("data",(r=>{u+=r})),null===(i=a.stderr)||void 0===i||i.on("data",(r=>{d+=r})),a.on("error",(r=>{c(r)})),a.on("close",((r,t)=>{void 0===a.pid?c(new Error("Process has no pid.")):e({pid:a.pid,stdout:u,stderr:d,status:r,signal:t})}))}catch(r){c(r)}}))},exports.zenkakuAlphanumericalsToHankaku=function(r){return r.replace(/[0-9A-Za-z]/g,(r=>{var t;return String.fromCodePoint((null!==(t=r.codePointAt(0))&&void 0!==t?t:0)-65248)}))};
1
+ "use strict";exports.ignoreEnoent=function(t){try{return t()}catch(t){if("object"==typeof t&&t&&"code"in t&&"ENOENT"===t.code)return;throw t}},exports.ignoreEnoentAsync=async function(t){try{return await t()}catch(t){if("object"==typeof t&&t&&"code"in t&&"ENOENT"===t.code)return;throw t}},exports.ignoreError=function(t){try{return t()}catch(t){}},exports.ignoreErrorAsync=async function(t){try{return await t()}catch(t){}},exports.shuffle=function(t){for(let r=t.length-1;r>0;r--){const n=Math.floor(Math.random()*(r+1));[t[r],t[n]]=[t[n],t[r]]}return t},exports.zenkakuAlphanumericalsToHankaku=function(t){return t.replace(/[0-9A-Za-z]/g,(t=>{var r;return String.fromCodePoint((null!==(r=t.codePointAt(0))&&void 0!==r?r:0)-65248)}))};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/error.ts","../../src/shuffle.ts","../../src/spawn.ts","../../src/zenkaku.ts"],"sourcesContent":["export function ignoreError<T>(fn: () => T): T | undefined {\n try {\n return fn();\n } catch {\n // do nothing\n }\n}\n\nexport function ignoreEnoent<T>(fn: () => T): T | undefined {\n try {\n return fn();\n } catch (error) {\n if (typeof error === 'object' && error && 'code' in error && error.code === 'ENOENT') {\n return;\n }\n throw error;\n }\n}\n\nexport async function ignoreErrorAsync<T>(fn: () => Promise<T>): Promise<T | undefined> {\n try {\n return await fn();\n } catch {\n // do nothing\n }\n}\n\nexport async function ignoreEnoentAsync<T>(fn: () => Promise<T>): Promise<T | undefined> {\n try {\n return await fn();\n } catch (error) {\n if (typeof error === 'object' && error && 'code' in error && error.code === 'ENOENT') {\n return;\n }\n throw error;\n }\n}\n","export function shuffle<T>(array: T[]): T[] {\n for (let index = array.length - 1; index > 0; index--) {\n const index_ = Math.floor(Math.random() * (index + 1));\n [array[index], array[index_]] = [array[index_], array[index]];\n }\n return array;\n}\n","import {\n spawn,\n SpawnOptions,\n SpawnOptionsWithoutStdio,\n SpawnOptionsWithStdioTuple,\n SpawnSyncReturns,\n StdioNull,\n StdioPipe,\n} from 'node:child_process';\n\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\nexport async function spawnAsync(\n command: string,\n args?: ReadonlyArray<string>,\n options?:\n | SpawnOptionsWithoutStdio\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>\n | SpawnOptions\n): Promise<SpawnAsyncReturns> {\n return new Promise((resolve, reject) => {\n try {\n const proc = spawn(command, args ?? [], options ?? {});\n let stdout = '';\n let stderr = '';\n\n proc.stdout?.on('data', (data) => {\n stdout += data;\n });\n proc.stderr?.on('data', (data) => {\n stderr += data;\n });\n\n proc.on('error', (error) => {\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n if (proc.pid === undefined) {\n reject(new Error('Process has no pid.'));\n } else {\n resolve({\n pid: proc.pid,\n stdout,\n stderr,\n status: code,\n signal,\n });\n }\n });\n } catch (error) {\n reject(error);\n }\n });\n}\n","export function zenkakuAlphanumericalsToHankaku(str: string): string {\n return str.replace(/[0-9A-Za-z]/g, (s: string) => {\n return String.fromCodePoint((s.codePointAt(0) ?? 0) - 0xfe_e0);\n });\n}\n"],"names":["fn","error","code","async","_unused","_unused2","array","index","length","index_","Math","floor","random","command","args","options","Promise","resolve","reject","_proc$stdout","_proc$stderr","proc","spawn","stdout","stderr","on","data","signal","undefined","pid","Error","status","str","replace","s","_s$codePointAt","String","fromCodePoint","codePointAt"],"mappings":"sEAQO,SAAyBA,GAC9B,IACE,OAAOA,GAMT,CALE,MAAOC,GACP,GAAqB,iBAAVA,GAAsBA,GAAS,SAAUA,GAAwB,WAAfA,EAAMC,KACjE,OAEF,MAAMD,CACR,CACF,4BAUOE,eAAoCH,GACzC,IACE,aAAaA,GAMf,CALE,MAAOC,GACP,GAAqB,iBAAVA,GAAsBA,GAAS,SAAUA,GAAwB,WAAfA,EAAMC,KACjE,OAEF,MAAMD,CACR,CACF,sBApCO,SAAw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ts"],"sourcesContent":["export function ignoreError<T>(fn: () => T): T | undefined {\n try {\n return fn();\n } catch {\n // do nothing\n }\n}\n\nexport function ignoreEnoent<T>(fn: () => T): T | undefined {\n try {\n return fn();\n } catch (error) {\n if (typeof error === 'object' && error && 'code' in error && error.code === 'ENOENT') {\n return;\n }\n throw error;\n }\n}\n\nexport async function ignoreErrorAsync<T>(fn: () => Promise<T>): Promise<T | undefined> {\n try {\n return await fn();\n } catch {\n // do nothing\n }\n}\n\nexport async function ignoreEnoentAsync<T>(fn: () => Promise<T>): Promise<T | undefined> {\n try {\n return await fn();\n } catch (error) {\n if (typeof error === 'object' && error && 'code' in error && error.code === 'ENOENT') {\n return;\n }\n throw error;\n }\n}\n","export function shuffle<T>(array: T[]): T[] {\n for (let index = array.length - 1; index > 0; index--) {\n const index_ = Math.floor(Math.random() * (index + 1));\n [array[index], array[index_]] = [array[index_], array[index]];\n }\n return array;\n}\n","export function zenkakuAlphanumericalsToHankaku(str: string): string {\n return str.replace(/[0-9A-Za-z]/g, (s: string) => {\n return String.fromCodePoint((s.codePointAt(0) ?? 0) - 0xfe_e0);\n });\n}\n"],"names":["fn","error","code","async","_unused","_unused2","array","index","length","index_","Math","floor","random","str","replace","s","_s$codePointAt","String","fromCodePoint","codePointAt"],"mappings":"kCAQO,SAAyBA,GAC9B,IACE,OAAOA,GAMT,CALE,MAAOC,GACP,GAAqB,iBAAVA,GAAsBA,GAAS,SAAUA,GAAwB,WAAfA,EAAMC,KACjE,OAEF,MAAMD,CACR,CACF,4BAUOE,eAAoCH,GACzC,IACE,aAAaA,GAMf,CALE,MAAOC,GACP,GAAqB,iBAAVA,GAAsBA,GAAS,SAAUA,GAAwB,WAAfA,EAAMC,KACjE,OAEF,MAAMD,CACR,CACF,sBApCO,SAAwBD,GAC7B,IACE,OAAOA,GAEP,CADA,MAAMI,GACN,CAEJ,2BAaOD,eAAmCH,GACxC,IACE,aAAaA,GAEb,CADA,MAAMK,GACN,CAEJ,kBCzBO,SAAoBC,GACzB,IAAK,IAAIC,EAAQD,EAAME,OAAS,EAAGD,EAAQ,EAAGA,IAAS,CACrD,MAAME,EAASC,KAAKC,MAAMD,KAAKE,UAAYL,EAAQ,KAClDD,EAAMC,GAAQD,EAAMG,IAAW,CAACH,EAAMG,GAASH,EAAMC,GACxD,CACA,OAAOD,CACT,0CCNO,SAAyCO,GAC9C,OAAOA,EAAIC,QAAQ,gBAAiBC,IAAc,IAAAC,EAChD,OAAOC,OAAOC,eAA+B,UAAhBH,EAAEI,YAAY,UAAE,IAAAH,EAAAA,EAAI,GAAK,MAAQ,GAElE"}
@@ -1,11 +1,7 @@
1
- /// <reference types="node" />
2
- import { SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, SpawnSyncReturns, StdioNull, StdioPipe } from "node:child_process";
3
1
  declare function ignoreError<T>(fn: () => T): T | undefined;
4
2
  declare function ignoreEnoent<T>(fn: () => T): T | undefined;
5
3
  declare function ignoreErrorAsync<T>(fn: () => Promise<T>): Promise<T | undefined>;
6
4
  declare function ignoreEnoentAsync<T>(fn: () => Promise<T>): Promise<T | undefined>;
7
5
  declare function shuffle<T>(array: T[]): T[];
8
- type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, "output" | "error">;
9
- declare function spawnAsync(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe> | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull> | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe> | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe> | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull> | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull> | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe> | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull> | SpawnOptions): Promise<SpawnAsyncReturns>;
10
6
  declare function zenkakuAlphanumericalsToHankaku(str: string): string;
11
- export { ignoreError, ignoreEnoent, ignoreErrorAsync, ignoreEnoentAsync, shuffle, spawnAsync, zenkakuAlphanumericalsToHankaku };
7
+ export { ignoreError, ignoreEnoent, ignoreErrorAsync, ignoreEnoentAsync, shuffle, zenkakuAlphanumericalsToHankaku };
@@ -1,4 +1,3 @@
1
- export { ignoreError, ignoreEnoent, ignoreErrorAsync, ignoreEnoentAsync } from "./error";
2
- export { shuffle } from "./shuffle";
3
- export { spawnAsync } from "./spawn";
4
- export { zenkakuAlphanumericalsToHankaku } from "./zenkaku";
1
+ export { ignoreError, ignoreEnoent, ignoreErrorAsync, ignoreEnoentAsync } from "./error.js";
2
+ export { shuffle } from "./shuffle.js";
3
+ export { zenkakuAlphanumericalsToHankaku } from "./zenkaku.js";
@@ -1,2 +1,2 @@
1
- export{ignoreEnoent,ignoreEnoentAsync,ignoreError,ignoreErrorAsync}from"./error.mjs";export{shuffle}from"./shuffle.mjs";export{spawnAsync}from"./spawn.mjs";export{zenkakuAlphanumericalsToHankaku}from"./zenkaku.mjs";
1
+ export{ignoreEnoent,ignoreEnoentAsync,ignoreError,ignoreErrorAsync}from"./error.mjs";export{shuffle}from"./shuffle.mjs";export{zenkakuAlphanumericalsToHankaku}from"./zenkaku.mjs";
2
2
  //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "@willbooster/shared-lib",
3
- "version": "1.8.1",
3
+ "version": "2.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "author": "WillBooster Inc.",
6
+ "sideEffects": false,
6
7
  "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/esm/index.d.mts",
11
+ "require": "./dist/cjs/index.cjs",
12
+ "import": "./dist/esm/index.mjs"
13
+ }
14
+ },
7
15
  "main": "dist/cjs/index.cjs",
8
16
  "module": "dist/esm/index.mjs",
9
17
  "types": "dist/cjs/index.d.cts",
@@ -12,7 +20,7 @@
12
20
  "dist/"
13
21
  ],
14
22
  "scripts": {
15
- "build": "build-ts build -t lib",
23
+ "build": "build-ts lib",
16
24
  "cleanup": "yarn format && yarn lint-fix",
17
25
  "format": "sort-package-json && yarn prettify",
18
26
  "lint": "eslint --color \"./{scripts,src,tests}/**/*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}\"",
@@ -30,8 +38,8 @@
30
38
  "@typescript-eslint/parser": "5.49.0",
31
39
  "@willbooster/eslint-config-ts": "10.0.8",
32
40
  "@willbooster/prettier-config": "9.1.1",
33
- "build-ts": "3.2.5",
34
- "eslint": "8.32.0",
41
+ "build-ts": "5.1.0",
42
+ "eslint": "8.33.0",
35
43
  "eslint-config-prettier": "8.6.0",
36
44
  "eslint-import-resolver-typescript": "3.5.3",
37
45
  "eslint-plugin-import": "2.27.5",
@@ -41,7 +49,7 @@
41
49
  "lint-staged": "13.1.0",
42
50
  "micromatch": "4.0.5",
43
51
  "prettier": "2.8.3",
44
- "sort-package-json": "2.2.0",
52
+ "sort-package-json": "2.3.0",
45
53
  "typescript": "4.9.4",
46
54
  "vitest": "0.28.3"
47
55
  },
@@ -1,5 +0,0 @@
1
- /// <reference types="node" />
2
- import { SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, SpawnSyncReturns, StdioNull, StdioPipe } from 'node:child_process';
3
- type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;
4
- declare function spawnAsync(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe> | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull> | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe> | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe> | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull> | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull> | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe> | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull> | SpawnOptions): Promise<SpawnAsyncReturns>;
5
- export { SpawnAsyncReturns, spawnAsync };
@@ -1,2 +0,0 @@
1
- import{spawn as o}from"node:child_process";async function r(r,n,t){return new Promise(((s,d)=>{try{var e,i;const l=o(r,null!=n?n:[],null!=t?t:{});let a="",c="";null===(e=l.stdout)||void 0===e||e.on("data",(o=>{a+=o})),null===(i=l.stderr)||void 0===i||i.on("data",(o=>{c+=o})),l.on("error",(o=>{d(o)})),l.on("close",((o,r)=>{void 0===l.pid?d(new Error("Process has no pid.")):s({pid:l.pid,stdout:a,stderr:c,status:o,signal:r})}))}catch(o){d(o)}}))}export{r as spawnAsync};
2
- //# sourceMappingURL=spawn.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spawn.mjs","sources":["../../src/spawn.ts"],"sourcesContent":["import {\n spawn,\n SpawnOptions,\n SpawnOptionsWithoutStdio,\n SpawnOptionsWithStdioTuple,\n SpawnSyncReturns,\n StdioNull,\n StdioPipe,\n} from 'node:child_process';\n\nexport type SpawnAsyncReturns = Omit<SpawnSyncReturns<string>, 'output' | 'error'>;\n\nexport async function spawnAsync(\n command: string,\n args?: ReadonlyArray<string>,\n options?:\n | SpawnOptionsWithoutStdio\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>\n | SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>\n | SpawnOptions\n): Promise<SpawnAsyncReturns> {\n return new Promise((resolve, reject) => {\n try {\n const proc = spawn(command, args ?? [], options ?? {});\n let stdout = '';\n let stderr = '';\n\n proc.stdout?.on('data', (data) => {\n stdout += data;\n });\n proc.stderr?.on('data', (data) => {\n stderr += data;\n });\n\n proc.on('error', (error) => {\n reject(error);\n });\n proc.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n if (proc.pid === undefined) {\n reject(new Error('Process has no pid.'));\n } else {\n resolve({\n pid: proc.pid,\n stdout,\n stderr,\n status: code,\n signal,\n });\n }\n });\n } catch (error) {\n reject(error);\n }\n });\n}\n"],"names":["async","spawnAsync","command","args","options","Promise","resolve","reject","_proc$stdout","_proc$stderr","proc","spawn","stdout","stderr","on","data","error","code","signal","undefined","pid","Error","status"],"mappings":"2CAYOA,eAAeC,EACpBC,EACAC,EACAC,GAYA,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,IAAI,IAAAC,EAAAC,EACF,MAAMC,EAAOC,EAAMT,EAASC,QAAAA,EAAQ,GAAIC,QAAAA,EAAW,CAAA,GACnD,IAAIQ,EAAS,GACTC,EAAS,GAEb,QAAAH,EAAAA,EAAKE,cAAL,IAAAJ,GAAAA,EAAaM,GAAG,QAASC,IACvBH,GAAUG,CAAI,IAEhB,QAAAL,EAAAA,EAAKG,cAAL,IAAAJ,GAAAA,EAAaK,GAAG,QAASC,IACvBF,GAAUE,CAAI,IAGhBL,EAAKI,GAAG,SAAUE,IAChBT,EAAOS,EAAM,IAEfN,EAAKI,GAAG,SAAS,CAACG,EAAqBC,UACpBC,IAAbT,EAAKU,IACPb,EAAO,IAAIc,MAAM,wBAEjBf,EAAQ,CACNc,IAAKV,EAAKU,IACVR,SACAC,SACAS,OAAQL,EACRC,UAEJ,GAIJ,CAFE,MAAOF,GACPT,EAAOS,EACT,IAEJ"}