@zenstackhq/common-helpers 3.0.0-alpha.10 → 3.0.0-alpha.11

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/index.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
7
  var __export = (target, all) => {
@@ -18,20 +16,11 @@ var __copyProps = (to, from, except, desc) => {
18
16
  }
19
17
  return to;
20
18
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
20
 
31
21
  // src/index.ts
32
22
  var src_exports = {};
33
23
  __export(src_exports, {
34
- findUp: () => findUp,
35
24
  invariant: () => invariant,
36
25
  isPlainObject: () => isPlainObject,
37
26
  lowerCaseFirst: () => lowerCaseFirst,
@@ -41,20 +30,6 @@ __export(src_exports, {
41
30
  });
42
31
  module.exports = __toCommonJS(src_exports);
43
32
 
44
- // src/find-up.ts
45
- var import_fs = __toESM(require("fs"), 1);
46
- var import_path = __toESM(require("path"), 1);
47
- function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
48
- if (!names.some((name) => !!name)) return void 0;
49
- const target = names.find((name) => import_fs.default.existsSync(import_path.default.join(cwd, name)));
50
- if (multiple === false && target) return import_path.default.join(cwd, target);
51
- if (target) result.push(import_path.default.join(cwd, target));
52
- const up = import_path.default.resolve(cwd, "..");
53
- if (up === cwd) return multiple && result.length > 0 ? result : void 0;
54
- return findUp(names, up, multiple, result);
55
- }
56
- __name(findUp, "findUp");
57
-
58
33
  // src/is-plain-object.ts
59
34
  function isObject(o) {
60
35
  return Object.prototype.toString.call(o) === "[object Object]";
@@ -122,7 +97,6 @@ function upperCaseFirst(input) {
122
97
  __name(upperCaseFirst, "upperCaseFirst");
123
98
  // Annotate the CommonJS export names for ESM import in node:
124
99
  0 && (module.exports = {
125
- findUp,
126
100
  invariant,
127
101
  isPlainObject,
128
102
  lowerCaseFirst,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/find-up.ts","../src/is-plain-object.ts","../src/lower-case-first.ts","../src/param-case.ts","../src/sleep.ts","../src/tiny-invariant.ts","../src/upper-case-first.ts"],"sourcesContent":["export * from './find-up';\nexport * from './is-plain-object';\nexport * from './lower-case-first';\nexport * from './param-case';\nexport * from './sleep';\nexport * from './tiny-invariant';\nexport * from './upper-case-first';\n","import fs from 'fs';\nimport path from 'path';\n\n/**\n * A type named FindUp that takes a type parameter e which extends boolean.\n */\nexport type FindUpResult<Multiple extends boolean> = Multiple extends true ? string[] | undefined : string | undefined;\n\n/**\n * Find and return file paths by searching parent directories based on the given names list and current working directory (cwd) path.\n * Optionally return a single path or multiple paths.\n * If multiple allowed, return all paths found.\n * If no paths are found, return undefined.\n *\n * @param names An array of strings representing names to search for within the directory\n * @param cwd A string representing the current working directory\n * @param multiple A boolean flag indicating whether to search for multiple levels. Useful for finding node_modules directories...\n * @param An array of strings representing the accumulated results used in multiple results\n * @returns Path(s) to a specific file or folder within the directory or parent directories\n */\nexport function findUp<Multiple extends boolean = false>(\n names: string[],\n cwd: string = process.cwd(),\n multiple: Multiple = false as Multiple,\n result: string[] = [],\n): FindUpResult<Multiple> {\n if (!names.some((name) => !!name)) return undefined;\n const target = names.find((name) => fs.existsSync(path.join(cwd, name)));\n if (multiple === false && target) return path.join(cwd, target) as FindUpResult<Multiple>;\n if (target) result.push(path.join(cwd, target));\n const up = path.resolve(cwd, '..');\n if (up === cwd) return (multiple && result.length > 0 ? result : undefined) as FindUpResult<Multiple>; // it'll fail anyway\n return findUp(names, up, multiple, result);\n}\n","function isObject(o: unknown) {\n return Object.prototype.toString.call(o) === '[object Object]';\n}\n\nexport function isPlainObject(o: unknown) {\n if (isObject(o) === false) return false;\n\n // If has modified constructor\n const ctor = (o as { constructor: unknown }).constructor;\n if (ctor === undefined) return true;\n\n // If has modified prototype\n const prot = (ctor as { prototype: unknown }).prototype;\n if (isObject(prot) === false) return false;\n\n // If constructor does not have an Object-specific method\n if (Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOf') === false) {\n return false;\n }\n\n // Most likely a plain Object\n return true;\n}\n","export function lowerCaseFirst(input: string) {\n return input.charAt(0).toLowerCase() + input.slice(1);\n}\n","const DEFAULT_SPLIT_REGEXP_1 = /([a-z0-9])([A-Z])/g;\nconst DEFAULT_SPLIT_REGEXP_2 = /([A-Z])([A-Z][a-z])/g;\nconst DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;\n\nexport function paramCase(input: string) {\n const result = input\n .replace(DEFAULT_SPLIT_REGEXP_1, '$1\\0$2')\n .replace(DEFAULT_SPLIT_REGEXP_2, '$1\\0$2')\n .replace(DEFAULT_STRIP_REGEXP, '\\0');\n\n let start = 0;\n let end = result.length;\n\n while (result.charAt(start) === '\\0') start++;\n while (result.charAt(end - 1) === '\\0') end--;\n\n return result\n .slice(start, end)\n .split('\\0')\n .map((str) => str.toLowerCase())\n .join('-');\n}\n","export function sleep(timeout: number) {\n return new Promise<void>((resolve) => {\n setTimeout(() => resolve(), timeout);\n });\n}\n","const isProduction = process.env['NODE_ENV'] === 'production';\nconst prefix = 'Invariant failed';\n\nexport function invariant(condition: unknown, message?: string): asserts condition {\n if (condition) {\n return;\n }\n\n if (isProduction) {\n throw new Error(prefix);\n }\n\n throw new Error(message ? `${prefix}: ${message}` : prefix);\n}\n","export function upperCaseFirst(input: string) {\n return input.charAt(0).toUpperCase() + input.slice(1);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;ACAA,gBAAe;AACf,kBAAiB;AAmBV,SAASA,OACZC,OACAC,MAAcC,QAAQD,IAAG,GACzBE,WAAqB,OACrBC,SAAmB,CAAA,GAAE;AAErB,MAAI,CAACJ,MAAMK,KAAK,CAACC,SAAS,CAAC,CAACA,IAAAA,EAAO,QAAOC;AAC1C,QAAMC,SAASR,MAAMS,KAAK,CAACH,SAASI,UAAAA,QAAGC,WAAWC,YAAAA,QAAKC,KAAKZ,KAAKK,IAAAA,CAAAA,CAAAA;AACjE,MAAIH,aAAa,SAASK,OAAQ,QAAOI,YAAAA,QAAKC,KAAKZ,KAAKO,MAAAA;AACxD,MAAIA,OAAQJ,QAAOU,KAAKF,YAAAA,QAAKC,KAAKZ,KAAKO,MAAAA,CAAAA;AACvC,QAAMO,KAAKH,YAAAA,QAAKI,QAAQf,KAAK,IAAA;AAC7B,MAAIc,OAAOd,IAAK,QAAQE,YAAYC,OAAOa,SAAS,IAAIb,SAASG;AACjE,SAAOR,OAAOC,OAAOe,IAAIZ,UAAUC,MAAAA;AACvC;AAbgBL;;;ACpBhB,SAASmB,SAASC,GAAU;AACxB,SAAOC,OAAOC,UAAUC,SAASC,KAAKJ,CAAAA,MAAO;AACjD;AAFSD;AAIF,SAASM,cAAcL,GAAU;AACpC,MAAID,SAASC,CAAAA,MAAO,MAAO,QAAO;AAGlC,QAAMM,OAAQN,EAA+B;AAC7C,MAAIM,SAASC,OAAW,QAAO;AAG/B,QAAMC,OAAQF,KAAgCJ;AAC9C,MAAIH,SAASS,IAAAA,MAAU,MAAO,QAAO;AAGrC,MAAIP,OAAOC,UAAUO,eAAeL,KAAKI,MAAM,eAAA,MAAq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","find","fs","existsSync","path","join","push","up","resolve","length","isObject","o","Object","prototype","toString","call","isPlainObject","ctor","undefined","prot","hasOwnProperty","lowerCaseFirst","input","charAt","toLowerCase","slice","DEFAULT_SPLIT_REGEXP_1","DEFAULT_SPLIT_REGEXP_2","DEFAULT_STRIP_REGEXP","paramCase","input","result","replace","start","end","length","charAt","slice","split","map","str","toLowerCase","join","sleep","timeout","Promise","resolve","setTimeout","isProduction","process","env","prefix","invariant","condition","message","Error","upperCaseFirst","input","charAt","toUpperCase","slice"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/is-plain-object.ts","../src/lower-case-first.ts","../src/param-case.ts","../src/sleep.ts","../src/tiny-invariant.ts","../src/upper-case-first.ts"],"sourcesContent":["export * from './is-plain-object';\nexport * from './lower-case-first';\nexport * from './param-case';\nexport * from './sleep';\nexport * from './tiny-invariant';\nexport * from './upper-case-first';\n","function isObject(o: unknown) {\n return Object.prototype.toString.call(o) === '[object Object]';\n}\n\nexport function isPlainObject(o: unknown) {\n if (isObject(o) === false) return false;\n\n // If has modified constructor\n const ctor = (o as { constructor: unknown }).constructor;\n if (ctor === undefined) return true;\n\n // If has modified prototype\n const prot = (ctor as { prototype: unknown }).prototype;\n if (isObject(prot) === false) return false;\n\n // If constructor does not have an Object-specific method\n if (Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOf') === false) {\n return false;\n }\n\n // Most likely a plain Object\n return true;\n}\n","export function lowerCaseFirst(input: string) {\n return input.charAt(0).toLowerCase() + input.slice(1);\n}\n","const DEFAULT_SPLIT_REGEXP_1 = /([a-z0-9])([A-Z])/g;\nconst DEFAULT_SPLIT_REGEXP_2 = /([A-Z])([A-Z][a-z])/g;\nconst DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;\n\nexport function paramCase(input: string) {\n const result = input\n .replace(DEFAULT_SPLIT_REGEXP_1, '$1\\0$2')\n .replace(DEFAULT_SPLIT_REGEXP_2, '$1\\0$2')\n .replace(DEFAULT_STRIP_REGEXP, '\\0');\n\n let start = 0;\n let end = result.length;\n\n while (result.charAt(start) === '\\0') start++;\n while (result.charAt(end - 1) === '\\0') end--;\n\n return result\n .slice(start, end)\n .split('\\0')\n .map((str) => str.toLowerCase())\n .join('-');\n}\n","export function sleep(timeout: number) {\n return new Promise<void>((resolve) => {\n setTimeout(() => resolve(), timeout);\n });\n}\n","const isProduction = process.env['NODE_ENV'] === 'production';\nconst prefix = 'Invariant failed';\n\nexport function invariant(condition: unknown, message?: string): asserts condition {\n if (condition) {\n return;\n }\n\n if (isProduction) {\n throw new Error(prefix);\n }\n\n throw new Error(message ? `${prefix}: ${message}` : prefix);\n}\n","export function upperCaseFirst(input: string) {\n return input.charAt(0).toUpperCase() + input.slice(1);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA,SAASA,SAASC,GAAU;AACxB,SAAOC,OAAOC,UAAUC,SAASC,KAAKJ,CAAAA,MAAO;AACjD;AAFSD;AAIF,SAASM,cAAcL,GAAU;AACpC,MAAID,SAASC,CAAAA,MAAO,MAAO,QAAO;AAGlC,QAAMM,OAAQN,EAA+B;AAC7C,MAAIM,SAASC,OAAW,QAAO;AAG/B,QAAMC,OAAQF,KAAgCJ;AAC9C,MAAIH,SAASS,IAAAA,MAAU,MAAO,QAAO;AAGrC,MAAIP,OAAOC,UAAUO,eAAeL,KAAKI,MAAM,eAAA,MAAqB,OAAO;AACvE,WAAO;EACX;AAGA,SAAO;AACX;AAlBgBH;;;ACJT,SAASK,eAAeC,OAAa;AACxC,SAAOA,MAAMC,OAAO,CAAA,EAAGC,YAAW,IAAKF,MAAMG,MAAM,CAAA;AACvD;AAFgBJ;;;ACAhB,IAAMK,yBAAyB;AAC/B,IAAMC,yBAAyB;AAC/B,IAAMC,uBAAuB;AAEtB,SAASC,UAAUC,OAAa;AACnC,QAAMC,SAASD,MACVE,QAAQN,wBAAwB,QAAA,EAChCM,QAAQL,wBAAwB,QAAA,EAChCK,QAAQJ,sBAAsB,IAAA;AAEnC,MAAIK,QAAQ;AACZ,MAAIC,MAAMH,OAAOI;AAEjB,SAAOJ,OAAOK,OAAOH,KAAAA,MAAW,KAAMA;AACtC,SAAOF,OAAOK,OAAOF,MAAM,CAAA,MAAO,KAAMA;AAExC,SAAOH,OACFM,MAAMJ,OAAOC,GAAAA,EACbI,MAAM,IAAA,EACNC,IAAI,CAACC,QAAQA,IAAIC,YAAW,CAAA,EAC5BC,KAAK,GAAA;AACd;AAjBgBb;;;ACJT,SAASc,MAAMC,SAAe;AACjC,SAAO,IAAIC,QAAc,CAACC,YAAAA;AACtBC,eAAW,MAAMD,QAAAA,GAAWF,OAAAA;EAChC,CAAA;AACJ;AAJgBD;;;ACAhB,IAAMK,eAAeC,QAAQC,IAAI,UAAA,MAAgB;AACjD,IAAMC,SAAS;AAER,SAASC,UAAUC,WAAoBC,SAAgB;AAC1D,MAAID,WAAW;AACX;EACJ;AAEA,MAAIL,cAAc;AACd,UAAM,IAAIO,MAAMJ,MAAAA;EACpB;AAEA,QAAM,IAAII,MAAMD,UAAU,GAAGH,MAAAA,KAAWG,OAAAA,KAAYH,MAAAA;AACxD;AAVgBC;;;ACHT,SAASI,eAAeC,OAAa;AACxC,SAAOA,MAAMC,OAAO,CAAA,EAAGC,YAAW,IAAKF,MAAMG,MAAM,CAAA;AACvD;AAFgBJ;","names":["isObject","o","Object","prototype","toString","call","isPlainObject","ctor","undefined","prot","hasOwnProperty","lowerCaseFirst","input","charAt","toLowerCase","slice","DEFAULT_SPLIT_REGEXP_1","DEFAULT_SPLIT_REGEXP_2","DEFAULT_STRIP_REGEXP","paramCase","input","result","replace","start","end","length","charAt","slice","split","map","str","toLowerCase","join","sleep","timeout","Promise","resolve","setTimeout","isProduction","process","env","prefix","invariant","condition","message","Error","upperCaseFirst","input","charAt","toUpperCase","slice"]}
package/dist/index.d.cts CHANGED
@@ -1,21 +1,3 @@
1
- /**
2
- * A type named FindUp that takes a type parameter e which extends boolean.
3
- */
4
- type FindUpResult<Multiple extends boolean> = Multiple extends true ? string[] | undefined : string | undefined;
5
- /**
6
- * Find and return file paths by searching parent directories based on the given names list and current working directory (cwd) path.
7
- * Optionally return a single path or multiple paths.
8
- * If multiple allowed, return all paths found.
9
- * If no paths are found, return undefined.
10
- *
11
- * @param names An array of strings representing names to search for within the directory
12
- * @param cwd A string representing the current working directory
13
- * @param multiple A boolean flag indicating whether to search for multiple levels. Useful for finding node_modules directories...
14
- * @param An array of strings representing the accumulated results used in multiple results
15
- * @returns Path(s) to a specific file or folder within the directory or parent directories
16
- */
17
- declare function findUp<Multiple extends boolean = false>(names: string[], cwd?: string, multiple?: Multiple, result?: string[]): FindUpResult<Multiple>;
18
-
19
1
  declare function isPlainObject(o: unknown): boolean;
20
2
 
21
3
  declare function lowerCaseFirst(input: string): string;
@@ -28,4 +10,4 @@ declare function invariant(condition: unknown, message?: string): asserts condit
28
10
 
29
11
  declare function upperCaseFirst(input: string): string;
30
12
 
31
- export { type FindUpResult, findUp, invariant, isPlainObject, lowerCaseFirst, paramCase, sleep, upperCaseFirst };
13
+ export { invariant, isPlainObject, lowerCaseFirst, paramCase, sleep, upperCaseFirst };
package/dist/index.d.ts CHANGED
@@ -1,21 +1,3 @@
1
- /**
2
- * A type named FindUp that takes a type parameter e which extends boolean.
3
- */
4
- type FindUpResult<Multiple extends boolean> = Multiple extends true ? string[] | undefined : string | undefined;
5
- /**
6
- * Find and return file paths by searching parent directories based on the given names list and current working directory (cwd) path.
7
- * Optionally return a single path or multiple paths.
8
- * If multiple allowed, return all paths found.
9
- * If no paths are found, return undefined.
10
- *
11
- * @param names An array of strings representing names to search for within the directory
12
- * @param cwd A string representing the current working directory
13
- * @param multiple A boolean flag indicating whether to search for multiple levels. Useful for finding node_modules directories...
14
- * @param An array of strings representing the accumulated results used in multiple results
15
- * @returns Path(s) to a specific file or folder within the directory or parent directories
16
- */
17
- declare function findUp<Multiple extends boolean = false>(names: string[], cwd?: string, multiple?: Multiple, result?: string[]): FindUpResult<Multiple>;
18
-
19
1
  declare function isPlainObject(o: unknown): boolean;
20
2
 
21
3
  declare function lowerCaseFirst(input: string): string;
@@ -28,4 +10,4 @@ declare function invariant(condition: unknown, message?: string): asserts condit
28
10
 
29
11
  declare function upperCaseFirst(input: string): string;
30
12
 
31
- export { type FindUpResult, findUp, invariant, isPlainObject, lowerCaseFirst, paramCase, sleep, upperCaseFirst };
13
+ export { invariant, isPlainObject, lowerCaseFirst, paramCase, sleep, upperCaseFirst };
package/dist/index.js CHANGED
@@ -1,20 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
- // src/find-up.ts
5
- import fs from "fs";
6
- import path from "path";
7
- function findUp(names, cwd = process.cwd(), multiple = false, result = []) {
8
- if (!names.some((name) => !!name)) return void 0;
9
- const target = names.find((name) => fs.existsSync(path.join(cwd, name)));
10
- if (multiple === false && target) return path.join(cwd, target);
11
- if (target) result.push(path.join(cwd, target));
12
- const up = path.resolve(cwd, "..");
13
- if (up === cwd) return multiple && result.length > 0 ? result : void 0;
14
- return findUp(names, up, multiple, result);
15
- }
16
- __name(findUp, "findUp");
17
-
18
4
  // src/is-plain-object.ts
19
5
  function isObject(o) {
20
6
  return Object.prototype.toString.call(o) === "[object Object]";
@@ -81,7 +67,6 @@ function upperCaseFirst(input) {
81
67
  }
82
68
  __name(upperCaseFirst, "upperCaseFirst");
83
69
  export {
84
- findUp,
85
70
  invariant,
86
71
  isPlainObject,
87
72
  lowerCaseFirst,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/find-up.ts","../src/is-plain-object.ts","../src/lower-case-first.ts","../src/param-case.ts","../src/sleep.ts","../src/tiny-invariant.ts","../src/upper-case-first.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\n/**\n * A type named FindUp that takes a type parameter e which extends boolean.\n */\nexport type FindUpResult<Multiple extends boolean> = Multiple extends true ? string[] | undefined : string | undefined;\n\n/**\n * Find and return file paths by searching parent directories based on the given names list and current working directory (cwd) path.\n * Optionally return a single path or multiple paths.\n * If multiple allowed, return all paths found.\n * If no paths are found, return undefined.\n *\n * @param names An array of strings representing names to search for within the directory\n * @param cwd A string representing the current working directory\n * @param multiple A boolean flag indicating whether to search for multiple levels. Useful for finding node_modules directories...\n * @param An array of strings representing the accumulated results used in multiple results\n * @returns Path(s) to a specific file or folder within the directory or parent directories\n */\nexport function findUp<Multiple extends boolean = false>(\n names: string[],\n cwd: string = process.cwd(),\n multiple: Multiple = false as Multiple,\n result: string[] = [],\n): FindUpResult<Multiple> {\n if (!names.some((name) => !!name)) return undefined;\n const target = names.find((name) => fs.existsSync(path.join(cwd, name)));\n if (multiple === false && target) return path.join(cwd, target) as FindUpResult<Multiple>;\n if (target) result.push(path.join(cwd, target));\n const up = path.resolve(cwd, '..');\n if (up === cwd) return (multiple && result.length > 0 ? result : undefined) as FindUpResult<Multiple>; // it'll fail anyway\n return findUp(names, up, multiple, result);\n}\n","function isObject(o: unknown) {\n return Object.prototype.toString.call(o) === '[object Object]';\n}\n\nexport function isPlainObject(o: unknown) {\n if (isObject(o) === false) return false;\n\n // If has modified constructor\n const ctor = (o as { constructor: unknown }).constructor;\n if (ctor === undefined) return true;\n\n // If has modified prototype\n const prot = (ctor as { prototype: unknown }).prototype;\n if (isObject(prot) === false) return false;\n\n // If constructor does not have an Object-specific method\n if (Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOf') === false) {\n return false;\n }\n\n // Most likely a plain Object\n return true;\n}\n","export function lowerCaseFirst(input: string) {\n return input.charAt(0).toLowerCase() + input.slice(1);\n}\n","const DEFAULT_SPLIT_REGEXP_1 = /([a-z0-9])([A-Z])/g;\nconst DEFAULT_SPLIT_REGEXP_2 = /([A-Z])([A-Z][a-z])/g;\nconst DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;\n\nexport function paramCase(input: string) {\n const result = input\n .replace(DEFAULT_SPLIT_REGEXP_1, '$1\\0$2')\n .replace(DEFAULT_SPLIT_REGEXP_2, '$1\\0$2')\n .replace(DEFAULT_STRIP_REGEXP, '\\0');\n\n let start = 0;\n let end = result.length;\n\n while (result.charAt(start) === '\\0') start++;\n while (result.charAt(end - 1) === '\\0') end--;\n\n return result\n .slice(start, end)\n .split('\\0')\n .map((str) => str.toLowerCase())\n .join('-');\n}\n","export function sleep(timeout: number) {\n return new Promise<void>((resolve) => {\n setTimeout(() => resolve(), timeout);\n });\n}\n","const isProduction = process.env['NODE_ENV'] === 'production';\nconst prefix = 'Invariant failed';\n\nexport function invariant(condition: unknown, message?: string): asserts condition {\n if (condition) {\n return;\n }\n\n if (isProduction) {\n throw new Error(prefix);\n }\n\n throw new Error(message ? `${prefix}: ${message}` : prefix);\n}\n","export function upperCaseFirst(input: string) {\n return input.charAt(0).toUpperCase() + input.slice(1);\n}\n"],"mappings":";;;;AAAA,OAAOA,QAAQ;AACf,OAAOC,UAAU;AAmBV,SAASC,OACZC,OACAC,MAAcC,QAAQD,IAAG,GACzBE,WAAqB,OACrBC,SAAmB,CAAA,GAAE;AAErB,MAAI,CAACJ,MAAMK,KAAK,CAACC,SAAS,CAAC,CAACA,IAAAA,EAAO,QAAOC;AAC1C,QAAMC,SAASR,MAAMS,KAAK,CAACH,SAASI,GAAGC,WAAWC,KAAKC,KAAKZ,KAAKK,IAAAA,CAAAA,CAAAA;AACjE,MAAIH,aAAa,SAASK,OAAQ,QAAOI,KAAKC,KAAKZ,KAAKO,MAAAA;AACxD,MAAIA,OAAQJ,QAAOU,KAAKF,KAAKC,KAAKZ,KAAKO,MAAAA,CAAAA;AACvC,QAAMO,KAAKH,KAAKI,QAAQf,KAAK,IAAA;AAC7B,MAAIc,OAAOd,IAAK,QAAQE,YAAYC,OAAOa,SAAS,IAAIb,SAASG;AACjE,SAAOR,OAAOC,OAAOe,IAAIZ,UAAUC,MAAAA;AACvC;AAbgBL;;;ACpBhB,SAASmB,SAASC,GAAU;AACxB,SAAOC,OAAOC,UAAUC,SAASC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;AAEA,MAAIL,cAAc;AACd,UAAM,IAAIO,MAAMJ,MAAAA;EACpB;AAEA,QAAM,IAAII,MAAMD,UAAU,GAAGH,MAAAA,KAAWG,OAAAA,KAAYH,MAAAA;AACxD;AAVgBC;;;ACHT,SAASI,eAAeC,OAAa;AACxC,SAAOA,MAAMC,OAAO,CAAA,EAAGC,YAAW,IAAKF,MAAMG,MAAM,CAAA;AACvD;AAFgBJ;","names":["fs","path","findUp","names","cwd","process","multiple","result","some","name","undefined","target","find","fs","existsSync","path","join","push","up","resolve","length","isObject","o","Object","prototype","toString","call","isPlainObject","ctor","undefined","prot","hasOwnProperty","lowerCaseFirst","input","charAt","toLowerCase","slice","DEFAULT_SPLIT_REGEXP_1","DEFAULT_SPLIT_REGEXP_2","DEFAULT_STRIP_REGEXP","paramCase","input","result","replace","start","end","length","charAt","slice","split","map","str","toLowerCase","join","sleep","timeout","Promise","resolve","setTimeout","isProduction","process","env","prefix","invariant","condition","message","Error","upperCaseFirst","input","charAt","toUpperCase","slice"]}
1
+ {"version":3,"sources":["../src/is-plain-object.ts","../src/lower-case-first.ts","../src/param-case.ts","../src/sleep.ts","../src/tiny-invariant.ts","../src/upper-case-first.ts"],"sourcesContent":["function isObject(o: unknown) {\n return Object.prototype.toString.call(o) === '[object Object]';\n}\n\nexport function isPlainObject(o: unknown) {\n if (isObject(o) === false) return false;\n\n // If has modified constructor\n const ctor = (o as { constructor: unknown }).constructor;\n if (ctor === undefined) return true;\n\n // If has modified prototype\n const prot = (ctor as { prototype: unknown }).prototype;\n if (isObject(prot) === false) return false;\n\n // If constructor does not have an Object-specific method\n if (Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOf') === false) {\n return false;\n }\n\n // Most likely a plain Object\n return true;\n}\n","export function lowerCaseFirst(input: string) {\n return input.charAt(0).toLowerCase() + input.slice(1);\n}\n","const DEFAULT_SPLIT_REGEXP_1 = /([a-z0-9])([A-Z])/g;\nconst DEFAULT_SPLIT_REGEXP_2 = /([A-Z])([A-Z][a-z])/g;\nconst DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;\n\nexport function paramCase(input: string) {\n const result = input\n .replace(DEFAULT_SPLIT_REGEXP_1, '$1\\0$2')\n .replace(DEFAULT_SPLIT_REGEXP_2, '$1\\0$2')\n .replace(DEFAULT_STRIP_REGEXP, '\\0');\n\n let start = 0;\n let end = result.length;\n\n while (result.charAt(start) === '\\0') start++;\n while (result.charAt(end - 1) === '\\0') end--;\n\n return result\n .slice(start, end)\n .split('\\0')\n .map((str) => str.toLowerCase())\n .join('-');\n}\n","export function sleep(timeout: number) {\n return new Promise<void>((resolve) => {\n setTimeout(() => resolve(), timeout);\n });\n}\n","const isProduction = process.env['NODE_ENV'] === 'production';\nconst prefix = 'Invariant failed';\n\nexport function invariant(condition: unknown, message?: string): asserts condition {\n if (condition) {\n return;\n }\n\n if (isProduction) {\n throw new Error(prefix);\n }\n\n throw new Error(message ? `${prefix}: ${message}` : prefix);\n}\n","export function upperCaseFirst(input: string) {\n return input.charAt(0).toUpperCase() + input.slice(1);\n}\n"],"mappings":";;;;AAAA,SAASA,SAASC,GAAU;AACxB,SAAOC,OAAOC,UAAUC,SAASC,KAAKJ,CAAAA,MAAO;AACjD;AAFSD;AAIF,SAASM,cAAcL,GAAU;AACpC,MAAID,SAASC,CAAAA,MAAO,MAAO,QAAO;AAGlC,QAAMM,OAAQN,EAA+B;AAC7C,MAAIM,SAASC,OAAW,QAAO;AAG/B,QAAMC,OAAQF,KAAgCJ;AAC9C,MAAIH,SAASS,IAAAA,MAAU,MAAO,QAAO;AAGrC,MAAIP,OAAOC,UAAUO,eAAeL,KAAKI,MAAM,eAAA,MAAqB,OAAO;AACvE,WAAO;EACX;AAGA,SAAO;AACX;AAlBgBH;;;ACJT,SAASK,eAAeC,OAAa;AACxC,SAAOA,MAAMC,OAAO,CAAA,EAAGC,YAAW,IAAKF,MAAMG,MAAM,CAAA;AACvD;AAFgBJ;;;ACAhB,IAAMK,yBAAyB;AAC/B,IAAMC,yBAAyB;AAC/B,IAAMC,uBAAuB;AAEtB,SAASC,UAAUC,OAAa;AACnC,QAAMC,SAASD,MACVE,QAAQN,wBAAwB,QAAA,EAChCM,QAAQL,wBAAwB,QAAA,EAChCK,QAAQJ,sBAAsB,IAAA;AAEnC,MAAIK,QAAQ;AACZ,MAAIC,MAAMH,OAAOI;AAEjB,SAAOJ,OAAOK,OAAOH,KAAAA,MAAW,KAAMA;AACtC,SAAOF,OAAOK,OAAOF,MAAM,CAAA,MAAO,KAAMA;AAExC,SAAOH,OACFM,MAAMJ,OAAOC,GAAAA,EACbI,MAAM,IAAA,EACNC,IAAI,CAACC,QAAQA,IAAIC,YAAW,CAAA,EAC5BC,KAAK,GAAA;AACd;AAjBgBb;;;ACJT,SAASc,MAAMC,SAAe;AACjC,SAAO,IAAIC,QAAc,CAACC,YAAAA;AACtBC,eAAW,MAAMD,QAAAA,GAAWF,OAAAA;EAChC,CAAA;AACJ;AAJgBD;;;ACAhB,IAAMK,eAAeC,QAAQC,IAAI,UAAA,MAAgB;AACjD,IAAMC,SAAS;AAER,SAASC,UAAUC,WAAoBC,SAAgB;AAC1D,MAAID,WAAW;AACX;EACJ;AAEA,MAAIL,cAAc;AACd,UAAM,IAAIO,MAAMJ,MAAAA;EACpB;AAEA,QAAM,IAAII,MAAMD,UAAU,GAAGH,MAAAA,KAAWG,OAAAA,KAAYH,MAAAA;AACxD;AAVgBC;;;ACHT,SAASI,eAAeC,OAAa;AACxC,SAAOA,MAAMC,OAAO,CAAA,EAAGC,YAAW,IAAKF,MAAMG,MAAM,CAAA;AACvD;AAFgBJ;","names":["isObject","o","Object","prototype","toString","call","isPlainObject","ctor","undefined","prot","hasOwnProperty","lowerCaseFirst","input","charAt","toLowerCase","slice","DEFAULT_SPLIT_REGEXP_1","DEFAULT_SPLIT_REGEXP_2","DEFAULT_STRIP_REGEXP","paramCase","input","result","replace","start","end","length","charAt","slice","split","map","str","toLowerCase","join","sleep","timeout","Promise","resolve","setTimeout","isProduction","process","env","prefix","invariant","condition","message","Error","upperCaseFirst","input","charAt","toUpperCase","slice"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenstackhq/common-helpers",
3
- "version": "3.0.0-alpha.10",
3
+ "version": "3.0.0-alpha.11",
4
4
  "description": "ZenStack Common Helpers",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -22,8 +22,8 @@
22
22
  }
23
23
  },
24
24
  "devDependencies": {
25
- "@zenstackhq/eslint-config": "3.0.0-alpha.10",
26
- "@zenstackhq/typescript-config": "3.0.0-alpha.10"
25
+ "@zenstackhq/typescript-config": "3.0.0-alpha.11",
26
+ "@zenstackhq/eslint-config": "3.0.0-alpha.11"
27
27
  },
28
28
  "scripts": {
29
29
  "build": "tsup-node",