@canonical/utils 0.10.0-experimental.0 → 0.10.0-experimental.3

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 (33) hide show
  1. package/dist/esm/humanizeNumber/constants.js +3 -0
  2. package/dist/esm/humanizeNumber/constants.js.map +1 -0
  3. package/dist/esm/humanizeNumber/humanizeNumber.js +73 -0
  4. package/dist/esm/humanizeNumber/humanizeNumber.js.map +1 -0
  5. package/dist/esm/humanizeNumber/index.js +2 -0
  6. package/dist/esm/humanizeNumber/index.js.map +1 -0
  7. package/dist/esm/humanizeNumber/types.js +2 -0
  8. package/dist/esm/humanizeNumber/types.js.map +1 -0
  9. package/dist/esm/index.js +2 -0
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/pluralize/index.js +2 -0
  12. package/dist/esm/pluralize/index.js.map +1 -0
  13. package/dist/esm/pluralize/pluralize.js +27 -0
  14. package/dist/esm/pluralize/pluralize.js.map +1 -0
  15. package/dist/esm/pluralize/types.js +2 -0
  16. package/dist/esm/pluralize/types.js.map +1 -0
  17. package/dist/types/humanizeNumber/constants.d.ts +3 -0
  18. package/dist/types/humanizeNumber/constants.d.ts.map +1 -0
  19. package/dist/types/humanizeNumber/humanizeNumber.d.ts +16 -0
  20. package/dist/types/humanizeNumber/humanizeNumber.d.ts.map +1 -0
  21. package/dist/types/humanizeNumber/index.d.ts +3 -0
  22. package/dist/types/humanizeNumber/index.d.ts.map +1 -0
  23. package/dist/types/humanizeNumber/types.d.ts +34 -0
  24. package/dist/types/humanizeNumber/types.d.ts.map +1 -0
  25. package/dist/types/index.d.ts +5 -1
  26. package/dist/types/index.d.ts.map +1 -1
  27. package/dist/types/pluralize/index.d.ts +3 -0
  28. package/dist/types/pluralize/index.d.ts.map +1 -0
  29. package/dist/types/pluralize/pluralize.d.ts +20 -0
  30. package/dist/types/pluralize/pluralize.d.ts.map +1 -0
  31. package/dist/types/pluralize/types.d.ts +5 -0
  32. package/dist/types/pluralize/types.d.ts.map +1 -0
  33. package/package.json +12 -7
@@ -0,0 +1,3 @@
1
+ export const DEFAULT_UNITS = ["", "k", "M", "B", "T"];
2
+ export const DEFAULT_MAGNITUDE_BASE = 1000;
3
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/humanizeNumber/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC"}
@@ -0,0 +1,73 @@
1
+ import { DEFAULT_MAGNITUDE_BASE, DEFAULT_UNITS } from "./constants.js";
2
+ /**
3
+ * Rounds a number using the Badge component's logic.
4
+ * Truncates to 3 characters and applies appropriate units.
5
+ * @param value The value to round
6
+ * @param units Array of unit suffixes
7
+ * @param magnitudeBase The base for scaling
8
+ * @param overflowIndicator Indicator to use when value exceeds maximum displayable value
9
+ * @param unit Current unit index
10
+ * @returns Object with displayValue and unit
11
+ */
12
+ const roundAndAddUnit = (value, units, magnitudeBase, overflowIndicator, unit = 0) => {
13
+ if (value < magnitudeBase) {
14
+ const truncatedValue = Number(value.toString().slice(0, 3));
15
+ return {
16
+ displayValue: `${truncatedValue}${units[unit]}${truncatedValue < value ? overflowIndicator || "" : ""}`,
17
+ unit: units[unit] || "",
18
+ };
19
+ }
20
+ // If the value exceeds the largest unit, cap it at `magnitudeBase - 1` of the largest unit and include the overflow indicator
21
+ if (unit >= units.length - 1) {
22
+ return {
23
+ displayValue: `${magnitudeBase - 1}${units[units.length - 1]}${overflowIndicator || ""}`,
24
+ unit: units[units.length - 1] || "",
25
+ };
26
+ }
27
+ const newValue = value / magnitudeBase;
28
+ return roundAndAddUnit(newValue, units, magnitudeBase, overflowIndicator, unit + 1);
29
+ };
30
+ /**
31
+ * Formats a large number into a compact, human-readable string with a unit suffix.
32
+ * This function returns a humanized representation of a number, along with the selected unit and the original value if needed for further processing.
33
+ *
34
+ * @param value The number to format. It is expected to be a finite, non-negative number.
35
+ * @param options Optional configuration for units, humanization type, and display constraints.
36
+ * @returns A formatted string representation of the number (e.g., "1.2k", "15M").
37
+ *
38
+ * @example
39
+ * humanizeNumber(12345); // Returns "12k"
40
+ * humanizeNumber(999999); // Returns "999k"
41
+ */
42
+ const humanizeNumber = (value, options) => {
43
+ const { magnitudeBase = DEFAULT_MAGNITUDE_BASE, overflowIndicator = "+" } = options ?? {};
44
+ let { units = DEFAULT_UNITS } = options ?? {};
45
+ // If user passes an undefined or empty units array, fallback to [""] to show no unit suffix instead of `undefined`
46
+ if (!units?.length)
47
+ units = [""];
48
+ // Display non-finite numbers (infinity, NaN) as-is
49
+ if (!Number.isFinite(value)) {
50
+ return {
51
+ displayValue: Number.isNaN(value) ? String(value) : "∞",
52
+ value,
53
+ unit: "",
54
+ };
55
+ }
56
+ // Floor the value to get integer part
57
+ const intValue = Math.floor(value);
58
+ if (intValue === 0) {
59
+ return {
60
+ displayValue: "0",
61
+ value,
62
+ unit: "",
63
+ };
64
+ }
65
+ const result = roundAndAddUnit(intValue, units, magnitudeBase, overflowIndicator);
66
+ return {
67
+ displayValue: result.displayValue,
68
+ value,
69
+ unit: result.unit,
70
+ };
71
+ };
72
+ export default humanizeNumber;
73
+ //# sourceMappingURL=humanizeNumber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"humanizeNumber.js","sourceRoot":"","sources":["../../../src/humanizeNumber/humanizeNumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGvE;;;;;;;;;GASG;AACH,MAAM,eAAe,GAAG,CACtB,KAAa,EACb,KAAe,EACf,aAAqB,EACrB,iBAAyB,EACzB,IAAI,GAAG,CAAC,EACgC,EAAE;IAC1C,IAAI,KAAK,GAAG,aAAa,EAAE,CAAC;QAC1B,MAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5D,OAAO;YACL,YAAY,EAAE,GAAG,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,cAAc,GAAG,KAAK,CAAC,CAAC,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;YACvG,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;SACxB,CAAC;IACJ,CAAC;IAED,8HAA8H;IAC9H,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO;YACL,YAAY,EAAE,GAAG,aAAa,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,iBAAiB,IAAI,EAAE,EAAE;YACxF,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE;SACpC,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,KAAK,GAAG,aAAa,CAAC;IACvC,OAAO,eAAe,CACpB,QAAQ,EACR,KAAK,EACL,aAAa,EACb,iBAAiB,EACjB,IAAI,GAAG,CAAC,CACT,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,cAAc,GAAG,CACrB,KAAa,EACb,OAA+B,EACf,EAAE;IAClB,MAAM,EAAE,aAAa,GAAG,sBAAsB,EAAE,iBAAiB,GAAG,GAAG,EAAE,GACvE,OAAO,IAAI,EAAE,CAAC;IAEhB,IAAI,EAAE,KAAK,GAAG,aAAa,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAE9C,mHAAmH;IACnH,IAAI,CAAC,KAAK,EAAE,MAAM;QAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;IAEjC,mDAAmD;IACnD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO;YACL,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG;YACvD,KAAK;YACL,IAAI,EAAE,EAAE;SACT,CAAC;IACJ,CAAC;IAED,sCAAsC;IACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAEnC,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO;YACL,YAAY,EAAE,GAAG;YACjB,KAAK;YACL,IAAI,EAAE,EAAE;SACT,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,eAAe,CAC5B,QAAQ,EACR,KAAK,EACL,aAAa,EACb,iBAAiB,CAClB,CAAC;IAEF,OAAO;QACL,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,KAAK;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default } from "./humanizeNumber.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/humanizeNumber/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/humanizeNumber/types.ts"],"names":[],"mappings":""}
package/dist/esm/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export { default as casing } from "./casing.js";
2
2
  export { default as debounce } from "./debounce.js";
3
+ export { default as humanizeNumber } from "./humanizeNumber/index.js";
3
4
  export { default as invariant } from "./invariant.js";
5
+ export { default as pluralize } from "./pluralize/index.js";
4
6
  export { default as throttle } from "./throttle.js";
5
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGpD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default } from "./pluralize.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pluralize/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Returns the pluralized form of a word based on the count.
3
+ * Aligns with Django's verbose_name and verbose_name_plural pattern.
4
+ * @param count - The count to determine singular or plural form.
5
+ * @param options - Options to customize the singular and plural forms. See {@link PluralizeOptions}.
6
+ * @returns The appropriate singular or plural form of the word, based on the `count`.
7
+ * @example
8
+ * pluralize(1) // returns 'item'
9
+ * pluralize(2) // returns 'items'
10
+ * pluralize(1, { singular: 'box', plural: 'boxes' }) // returns 'box'
11
+ * pluralize(3, { singular: 'box', plural: 'boxes' }) // returns 'boxes'
12
+ * pluralize(1, { singular: 'child', plural: 'children' }) // returns 'child'
13
+ * pluralize(3, { singular: 'child', plural: 'children' }) // returns 'children'
14
+ * pluralize(1, { singular: 'person' }) // returns 'person'
15
+ * pluralize(2, { singular: 'person' }) // returns 'persons'
16
+ */
17
+ const pluralize = (count, options) => {
18
+ options ||= {};
19
+ const { singular = "item", plural } = options;
20
+ if (count === 1) {
21
+ return singular;
22
+ }
23
+ // If plural is provided, use it; otherwise default to singular + 's'
24
+ return plural || `${singular}s`;
25
+ };
26
+ export default pluralize;
27
+ //# sourceMappingURL=pluralize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluralize.js","sourceRoot":"","sources":["../../../src/pluralize/pluralize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,OAA0B,EAAU,EAAE;IACtE,OAAO,KAAK,EAAE,CAAC;IACf,MAAM,EAAE,QAAQ,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAE9C,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,qEAAqE;IACrE,OAAO,MAAM,IAAI,GAAG,QAAQ,GAAG,CAAC;AAClC,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/pluralize/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_UNITS: string[];
2
+ export declare const DEFAULT_MAGNITUDE_BASE = 1000;
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/humanizeNumber/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,UAA2B,CAAC;AACtD,eAAO,MAAM,sBAAsB,OAAO,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { HumanizeNumberOptions, HumanizeResult } from "./types.js";
2
+ /**
3
+ * Formats a large number into a compact, human-readable string with a unit suffix.
4
+ * This function returns a humanized representation of a number, along with the selected unit and the original value if needed for further processing.
5
+ *
6
+ * @param value The number to format. It is expected to be a finite, non-negative number.
7
+ * @param options Optional configuration for units, humanization type, and display constraints.
8
+ * @returns A formatted string representation of the number (e.g., "1.2k", "15M").
9
+ *
10
+ * @example
11
+ * humanizeNumber(12345); // Returns "12k"
12
+ * humanizeNumber(999999); // Returns "999k"
13
+ */
14
+ declare const humanizeNumber: (value: number, options?: HumanizeNumberOptions) => HumanizeResult;
15
+ export default humanizeNumber;
16
+ //# sourceMappingURL=humanizeNumber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"humanizeNumber.d.ts","sourceRoot":"","sources":["../../../src/humanizeNumber/humanizeNumber.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA4CxE;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,cAAc,GAClB,OAAO,MAAM,EACb,UAAU,qBAAqB,KAC9B,cAyCF,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { default } from "./humanizeNumber.js";
2
+ export type * from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/humanizeNumber/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,mBAAmB,YAAY,CAAC"}
@@ -0,0 +1,34 @@
1
+ export type HumanizeNumberOptions = {
2
+ /**
3
+ * The array of unit suffixes to use, starting with the base unit (e.g., "").
4
+ * @default ["", "k", "M", "B", "T"]
5
+ */
6
+ units?: string[];
7
+ /**
8
+ * The base for the magnitude calculation.
9
+ * This is typically 1000 for thousands, millions, etc.
10
+ * If set to 10, it will use powers of 10 instead.
11
+ * You might also use 1024 for binary prefixes (Ki, Mi, etc.).
12
+ * @default 1000
13
+ */
14
+ magnitudeBase?: number;
15
+ /**
16
+ * Append this string to the display value to indicate truncation when the number has been truncated, indicating a loss of information due to rounding.
17
+ */
18
+ overflowIndicator?: string;
19
+ };
20
+ /**
21
+ * Represents the result of humanizing a number.
22
+ */
23
+ export interface HumanizeResult {
24
+ /** The formatted value as a string, e.g., "1.2k" */
25
+ displayValue: string;
26
+ /** The numeric value before formatting, e.g., 1200 */
27
+ value: number;
28
+ /**
29
+ * The unit suffix that was appended to the value, e.g., "k"
30
+ * This might be useful for separately handling the unit, such as in aria labels.
31
+ * */
32
+ unit?: string;
33
+ }
34
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/humanizeNumber/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IAEjB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,KAAK,EAAE,MAAM,CAAC;IACd;;;SAGK;IACL,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
@@ -1,6 +1,10 @@
1
1
  export { default as casing } from "./casing.js";
2
2
  export { default as debounce } from "./debounce.js";
3
+ export type * from "./humanizeNumber/index.js";
4
+ export { default as humanizeNumber } from "./humanizeNumber/index.js";
3
5
  export { default as invariant } from "./invariant.js";
6
+ export type * from "./pluralize/index.js";
7
+ export { default as pluralize } from "./pluralize/index.js";
4
8
  export { default as throttle } from "./throttle.js";
5
- export type { AllOrNone } from "./types.js";
9
+ export type * from "./types.js";
6
10
  //# 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,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEpD,mBAAmB,2BAA2B,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,mBAAmB,sBAAsB,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEpD,mBAAmB,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { default } from "./pluralize.js";
2
+ export type * from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pluralize/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,mBAAmB,YAAY,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { PluralizeOptions } from "./types.js";
2
+ /**
3
+ * Returns the pluralized form of a word based on the count.
4
+ * Aligns with Django's verbose_name and verbose_name_plural pattern.
5
+ * @param count - The count to determine singular or plural form.
6
+ * @param options - Options to customize the singular and plural forms. See {@link PluralizeOptions}.
7
+ * @returns The appropriate singular or plural form of the word, based on the `count`.
8
+ * @example
9
+ * pluralize(1) // returns 'item'
10
+ * pluralize(2) // returns 'items'
11
+ * pluralize(1, { singular: 'box', plural: 'boxes' }) // returns 'box'
12
+ * pluralize(3, { singular: 'box', plural: 'boxes' }) // returns 'boxes'
13
+ * pluralize(1, { singular: 'child', plural: 'children' }) // returns 'child'
14
+ * pluralize(3, { singular: 'child', plural: 'children' }) // returns 'children'
15
+ * pluralize(1, { singular: 'person' }) // returns 'person'
16
+ * pluralize(2, { singular: 'person' }) // returns 'persons'
17
+ */
18
+ declare const pluralize: (count: number, options?: PluralizeOptions) => string;
19
+ export default pluralize;
20
+ //# sourceMappingURL=pluralize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluralize.d.ts","sourceRoot":"","sources":["../../../src/pluralize/pluralize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;;;;GAeG;AACH,QAAA,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,UAAU,gBAAgB,KAAG,MAU9D,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,5 @@
1
+ export type PluralizeOptions = {
2
+ singular?: string;
3
+ plural?: string;
4
+ };
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/pluralize/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAE7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
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.10.0-experimental.0",
4
+ "version": "0.10.0-experimental.3",
5
5
  "type": "module",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
@@ -36,13 +36,18 @@
36
36
  "check:biome": "biome check",
37
37
  "check:biome:fix": "biome check --write",
38
38
  "check:ts": "tsc --noEmit",
39
- "test": "echo 'No tests defined yet'"
39
+ "test": "bun run test:vitest",
40
+ "test:vitest": "vitest run",
41
+ "test:vitest:watch": "vitest"
40
42
  },
41
43
  "devDependencies": {
42
- "@biomejs/biome": "^2.0.0",
43
- "@canonical/biome-config": "^0.10.0-experimental.0",
44
- "@canonical/typescript-config-base": "^0.10.0-experimental.0",
45
- "typescript": "^5.8.3"
44
+ "@biomejs/biome": "2.2.2",
45
+ "@canonical/biome-config": "^0.10.0-experimental.3",
46
+ "@canonical/typescript-config-base": "^0.10.0-experimental.3",
47
+ "globals": "^16.2.0",
48
+ "typescript": "^5.8.3",
49
+ "vite": "^7.0.0",
50
+ "vitest": "^3.2.3"
46
51
  },
47
- "gitHead": "d38f742073a1a0e582ce138bf0eb6dd63889721b"
52
+ "gitHead": "99c01818f83645f82a1a8971e5da18ce35eff68c"
48
53
  }