@clerc/utils 1.1.0 → 1.1.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -38
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,38 +1 @@
1
- //#region src/index.ts
2
- const looseIsArray = (arr) => Array.isArray(arr);
3
- const toArray = (a) => Array.isArray(a) ? a : [a];
4
- /**
5
- * Converts a dash- or space-separated string to camelCase. Not using regexp for
6
- * better performance, because this function is used in parser.
7
- */
8
- function camelCase(str) {
9
- const firstIdx = Math.min(str.includes("-") ? str.indexOf("-") : Infinity, str.includes(" ") ? str.indexOf(" ") : Infinity);
10
- if (firstIdx === Infinity) return str;
11
- let result = str.slice(0, firstIdx);
12
- for (let i = firstIdx; i < str.length; i++) if ((str[i] === "-" || str[i] === " ") && i + 1 < str.length) {
13
- const nextChar = str.charCodeAt(i + 1);
14
- if (nextChar >= 97 && nextChar <= 122) {
15
- result += String.fromCharCode(nextChar - 32);
16
- i++;
17
- } else {
18
- result += str[i + 1];
19
- i++;
20
- }
21
- } else if (str[i] !== "-" && str[i] !== " ") result += str[i];
22
- return result;
23
- }
24
- function joinWithAnd(values) {
25
- if (values.length === 0) return "";
26
- if (values.length === 1) return values[0];
27
- const last = values.pop();
28
- return `${values.join(", ")} and ${last}`;
29
- }
30
- const kebabCase = (s) => s.replace(/([A-Z])/g, (_, c) => `-${c.toLowerCase()}`);
31
- const formatFlagName = (n) => n.length <= 1 ? `-${n}` : `--${kebabCase(n)}`;
32
- const formatVersion = (v) => v.length === 0 ? "" : v.startsWith("v") ? v : `v${v}`;
33
- const isTruthy = Boolean;
34
- const objectIsEmpty = (obj) => Object.keys(obj).length === 0;
35
- const resolveValue = (value) => typeof value === "function" ? value() : value;
36
-
37
- //#endregion
38
- export { camelCase, formatFlagName, formatVersion, isTruthy, joinWithAnd, kebabCase, looseIsArray, objectIsEmpty, resolveValue, toArray };
1
+ const e=e=>Array.isArray(e),t=e=>Array.isArray(e)?e:[e];function n(e){let t=Math.min(e.includes(`-`)?e.indexOf(`-`):1/0,e.includes(` `)?e.indexOf(` `):1/0);if(t===1/0)return e;let n=e.slice(0,t);for(let r=t;r<e.length;r++)if((e[r]===`-`||e[r]===` `)&&r+1<e.length){let t=e.charCodeAt(r+1);t>=97&&t<=122?(n+=String.fromCharCode(t-32),r++):(n+=e[r+1],r++)}else e[r]!==`-`&&e[r]!==` `&&(n+=e[r]);return n}function r(e){if(e.length===0)return``;if(e.length===1)return e[0];let t=e.pop();return`${e.join(`, `)} and ${t}`}const i=e=>e.replace(/([A-Z])/g,(e,t)=>`-${t.toLowerCase()}`),a=e=>e.length<=1?`-${e}`:`--${i(e)}`,o=e=>e.length===0?``:e.startsWith(`v`)?e:`v${e}`,s=Boolean,c=e=>Object.keys(e).length===0,l=e=>typeof e==`function`?e():e;export{n as camelCase,a as formatFlagName,o as formatVersion,s as isTruthy,r as joinWithAnd,i as kebabCase,e as looseIsArray,c as objectIsEmpty,l as resolveValue,t as toArray};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/utils",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "type": "module",
6
6
  "description": "Clerc utils",