@canonical/utils 0.7.1-experimental.0 → 0.9.0-experimental.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.
@@ -42,9 +42,25 @@ const toCamelCase = (s) => {
42
42
  .replaceAll("_", "")
43
43
  .replaceAll(" ", "");
44
44
  };
45
+ /**
46
+ * Check if a string is in PascalCase.
47
+ * @param s - The string to check
48
+ * @returns True if the string is in PascalCase, false otherwise.
49
+ * @example
50
+ * isPascalCase("MyComponent") // true
51
+ * isPascalCase("myComponent") // false
52
+ */
53
+ const isPascalCase = (s) => {
54
+ // A simple regular expression that requires:
55
+ // - the string to start with an uppercase letter
56
+ // - followed by zero or more lowercase letters or digits,
57
+ // - then zero or more groups that start with an uppercase letter followed by zero or more lowercase letters or digits.
58
+ return /^[A-Z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/.test(s);
59
+ };
45
60
  export default {
46
61
  toPascalCase,
47
62
  toKebabCase,
48
63
  toCamelCase,
64
+ isPascalCase,
49
65
  };
50
66
  //# sourceMappingURL=casing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"casing.js","sourceRoot":"","sources":["../../src/casing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,YAAY,GAAG,CAAC,CAAS,EAAU,EAAE;IACzC,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAElB,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;IAElC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,GAAG,CAAC,CAAS,EAAU,EAAE;IACxC,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAElB,OAAO,CAAC;SACL,IAAI,EAAE;SACN,OAAO,CAAC,oBAAoB,EAAE,O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SACL,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;SAC/C,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;SACnB,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;SACnB,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AACzB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,YAAY,GAAG,CAAC,CAAS,EAAW,EAAE;IAC1C,6CAA6C;IAC7C,iDAAiD;IACjD,0DAA0D;IAC1D,uHAAuH;IACvH,OAAO,qCAAqC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF,eAAe;IACb,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;CACb,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as debounce } from "./debounce.js";
2
2
  export { default as throttle } from "./throttle.js";
3
3
  export { default as casing } from "./casing.js";
4
+ export { default as invariant } from "./invariant.js";
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Asserts that the given condition is truthy.
3
+ *
4
+ * @remarks
5
+ * This is a minimalist invariant function. It throws an error with the provided message
6
+ * (or a default one) if the condition is falsy. Unlike a more basic implementation, this version
7
+ * supports lazy evaluation of the message (if provided as a function) and allows a custom prefix to be added.
8
+ *
9
+ * Tiny-invariant includes additional branches to:
10
+ * - Check the runtime environment (development vs. production) and strip detailed messages in production.
11
+ *
12
+ * If you need these extra features (e.g., for optimized production bundles), tiny-invariant may
13
+ * be a better choice. However, if simplicity and minimal code are your priorities, this version
14
+ * may suffice.
15
+ *
16
+ * @param condition - The condition to assert. If falsy, an error is thrown.
17
+ * @param message - Optional error message or a function that returns an error message. If not provided, a default message is used.
18
+ * @param prefix - Optional prefix for the error message. Defaults to 'Invariant violation'.
19
+ *
20
+ * @throws {Error} If the condition is falsy.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const value: string | undefined = getValue();
25
+ * invariant(typeof value === 'string', 'Expected value to be a string');
26
+ * // After this assertion, TypeScript narrows `value` to `string`.
27
+ *
28
+ * // With a custom prefix and lazy evaluation:
29
+ * invariant(value !== null, () => `Value should not be null, got ${value}`, 'Type Error');
30
+ * ```
31
+ */
32
+ export default (condition, message, prefix = "Invariant violation") => {
33
+ if (!condition) {
34
+ const resolvedMessage = typeof message === "function" ? message() : message;
35
+ throw new Error(resolvedMessage ? `${prefix}: ${resolvedMessage}` : prefix);
36
+ }
37
+ };
38
+ //# sourceMappingURL=invariant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invariant.js","sourceRoot":"","sources":["../../src/invariant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAe,CACb,SAAkB,EAClB,OAAiC,EACjC,MAAM,GAAG,qBAAqB,EACX,EAAE;IACrB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,eAAe,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,MAAM,KAAK,eAAe,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC,CAAC"}
@@ -2,6 +2,7 @@ declare const _default: {
2
2
  toPascalCase: (s: string) => string;
3
3
  toKebabCase: (s: string) => string;
4
4
  toCamelCase: (s: string) => string;
5
+ isPascalCase: (s: string) => boolean;
5
6
  };
6
7
  export default _default;
7
8
  //# sourceMappingURL=casing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"casing.d.ts","sourceRoot":"","sources":["../../src/casing.ts"],"names":[],"mappings":";sBAOyB,MAAM,KAAG,MAAM;qBAehB,MAAM,KAAG,MAAM;qBAgBf,MAAM,KAAG,MAAM;;AAUvC,wBAIE"}
1
+ {"version":3,"file":"casing.d.ts","sourceRoot":"","sources":["../../src/casing.ts"],"names":[],"mappings":";sBAOyB,MAAM,KAAG,MAAM;qBAehB,MAAM,KAAG,MAAM;qBAgBf,MAAM,KAAG,MAAM;sBAkBd,MAAM,KAAG,OAAO;;AAQzC,wBAKE"}
@@ -1,4 +1,5 @@
1
1
  export { default as debounce } from "./debounce.js";
2
2
  export { default as throttle } from "./throttle.js";
3
3
  export { default as casing } from "./casing.js";
4
+ export { default as invariant } from "./invariant.js";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Asserts that the given condition is truthy.
3
+ *
4
+ * @remarks
5
+ * This is a minimalist invariant function. It throws an error with the provided message
6
+ * (or a default one) if the condition is falsy. Unlike a more basic implementation, this version
7
+ * supports lazy evaluation of the message (if provided as a function) and allows a custom prefix to be added.
8
+ *
9
+ * Tiny-invariant includes additional branches to:
10
+ * - Check the runtime environment (development vs. production) and strip detailed messages in production.
11
+ *
12
+ * If you need these extra features (e.g., for optimized production bundles), tiny-invariant may
13
+ * be a better choice. However, if simplicity and minimal code are your priorities, this version
14
+ * may suffice.
15
+ *
16
+ * @param condition - The condition to assert. If falsy, an error is thrown.
17
+ * @param message - Optional error message or a function that returns an error message. If not provided, a default message is used.
18
+ * @param prefix - Optional prefix for the error message. Defaults to 'Invariant violation'.
19
+ *
20
+ * @throws {Error} If the condition is falsy.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const value: string | undefined = getValue();
25
+ * invariant(typeof value === 'string', 'Expected value to be a string');
26
+ * // After this assertion, TypeScript narrows `value` to `string`.
27
+ *
28
+ * // With a custom prefix and lazy evaluation:
29
+ * invariant(value !== null, () => `Value should not be null, got ${value}`, 'Type Error');
30
+ * ```
31
+ */
32
+ declare const _default: (condition: unknown, message?: string | (() => string), prefix?: string) => asserts condition;
33
+ export default _default;
34
+ //# sourceMappingURL=invariant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../../src/invariant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;oCAEU,OAAO,YACR,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,sBAEhC,QAAQ,SAAS;AAJpB,wBASE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@canonical/utils",
3
3
  "description": "Standard utility functions for Canonical's Web Engineering team",
4
- "version": "0.7.1-experimental.0",
4
+ "version": "0.9.0-experimental.0",
5
5
  "type": "module",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -42,5 +42,5 @@
42
42
  "@canonical/typescript-config-base": "^0.4.0-experimental.0",
43
43
  "typescript": "^5.7.2"
44
44
  },
45
- "gitHead": "636cd2e447a1f2bb67e636169d6cbb5171e6fca6"
45
+ "gitHead": "5d06233e70975e9ccc475c2d13de7e2ff8769c44"
46
46
  }