@skmtc/core 0.0.792 → 0.0.793

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 (71) hide show
  1. package/esm/dsl/GeneratedValueList.d.ts +158 -0
  2. package/esm/dsl/GeneratedValueList.d.ts.map +1 -1
  3. package/esm/dsl/GeneratedValueList.js +158 -0
  4. package/esm/dsl/Stringable.d.ts +76 -0
  5. package/esm/dsl/Stringable.d.ts.map +1 -1
  6. package/esm/dsl/Stringable.js +75 -0
  7. package/esm/helpers/collateExamples.d.ts +150 -0
  8. package/esm/helpers/collateExamples.d.ts.map +1 -1
  9. package/esm/helpers/collateExamples.js +145 -0
  10. package/esm/helpers/formatNumber.d.ts +95 -0
  11. package/esm/helpers/formatNumber.d.ts.map +1 -1
  12. package/esm/helpers/formatNumber.js +95 -0
  13. package/esm/helpers/generationStats.d.ts +287 -1
  14. package/esm/helpers/generationStats.d.ts.map +1 -1
  15. package/esm/helpers/generationStats.js +266 -0
  16. package/esm/helpers/isEmpty.d.ts +62 -0
  17. package/esm/helpers/isEmpty.d.ts.map +1 -1
  18. package/esm/helpers/isEmpty.js +62 -0
  19. package/esm/helpers/isImported.d.ts +80 -0
  20. package/esm/helpers/isImported.d.ts.map +1 -1
  21. package/esm/helpers/isImported.js +80 -0
  22. package/esm/helpers/parseModuleName.d.ts +175 -0
  23. package/esm/helpers/parseModuleName.d.ts.map +1 -1
  24. package/esm/helpers/parseModuleName.js +153 -0
  25. package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
  26. package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  27. package/esm/helpers/toResolvedArtifactPath.js +140 -0
  28. package/esm/oas/schema/Schema.d.ts +117 -0
  29. package/esm/oas/schema/Schema.d.ts.map +1 -1
  30. package/esm/typescript/identifiers.d.ts +159 -0
  31. package/esm/typescript/identifiers.d.ts.map +1 -1
  32. package/esm/typescript/identifiers.js +159 -0
  33. package/esm/typescript/withDescription.d.ts +119 -0
  34. package/esm/typescript/withDescription.d.ts.map +1 -1
  35. package/esm/typescript/withDescription.js +119 -0
  36. package/package.json +1 -1
  37. package/script/dsl/GeneratedValueList.d.ts +158 -0
  38. package/script/dsl/GeneratedValueList.d.ts.map +1 -1
  39. package/script/dsl/GeneratedValueList.js +158 -0
  40. package/script/dsl/Stringable.d.ts +76 -0
  41. package/script/dsl/Stringable.d.ts.map +1 -1
  42. package/script/dsl/Stringable.js +75 -0
  43. package/script/helpers/collateExamples.d.ts +150 -0
  44. package/script/helpers/collateExamples.d.ts.map +1 -1
  45. package/script/helpers/collateExamples.js +145 -0
  46. package/script/helpers/formatNumber.d.ts +95 -0
  47. package/script/helpers/formatNumber.d.ts.map +1 -1
  48. package/script/helpers/formatNumber.js +95 -0
  49. package/script/helpers/generationStats.d.ts +287 -1
  50. package/script/helpers/generationStats.d.ts.map +1 -1
  51. package/script/helpers/generationStats.js +266 -0
  52. package/script/helpers/isEmpty.d.ts +62 -0
  53. package/script/helpers/isEmpty.d.ts.map +1 -1
  54. package/script/helpers/isEmpty.js +62 -0
  55. package/script/helpers/isImported.d.ts +80 -0
  56. package/script/helpers/isImported.d.ts.map +1 -1
  57. package/script/helpers/isImported.js +80 -0
  58. package/script/helpers/parseModuleName.d.ts +175 -0
  59. package/script/helpers/parseModuleName.d.ts.map +1 -1
  60. package/script/helpers/parseModuleName.js +153 -0
  61. package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
  62. package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  63. package/script/helpers/toResolvedArtifactPath.js +140 -0
  64. package/script/oas/schema/Schema.d.ts +117 -0
  65. package/script/oas/schema/Schema.d.ts.map +1 -1
  66. package/script/typescript/identifiers.d.ts +159 -0
  67. package/script/typescript/identifiers.d.ts.map +1 -1
  68. package/script/typescript/identifiers.js +159 -0
  69. package/script/typescript/withDescription.d.ts +119 -0
  70. package/script/typescript/withDescription.d.ts.map +1 -1
  71. package/script/typescript/withDescription.js +119 -0
@@ -1,10 +1,160 @@
1
1
  import "../_dnt.polyfills.js";
2
2
  import type { OasRef } from '../oas/ref/Ref.js';
3
3
  import type { OasSchema } from '../oas/schema/Schema.js';
4
+ /**
5
+ * Arguments for collating examples from OpenAPI schemas.
6
+ */
4
7
  type CollatedExampleArgs = {
8
+ /** The OpenAPI schema or reference to extract examples from */
5
9
  objectSchema: OasSchema | OasRef<'schema'> | undefined;
10
+ /** Current recursion depth (used to prevent infinite loops) */
6
11
  depth: number;
7
12
  };
13
+ /**
14
+ * Recursively collates and builds example values from OpenAPI schemas.
15
+ *
16
+ * This function traverses OpenAPI schema structures and generates comprehensive
17
+ * example values based on the schema definitions and any explicit examples provided.
18
+ * It handles complex nested structures including objects, arrays, unions, and
19
+ * references while preventing infinite recursion through depth limiting.
20
+ *
21
+ * The function prioritizes explicit examples when available and falls back to
22
+ * generating examples from nested schemas. It's particularly useful for creating
23
+ * realistic test data, API documentation examples, and mock responses.
24
+ *
25
+ * @param args - Configuration for example collation
26
+ * @param args.objectSchema - The schema to extract examples from
27
+ * @param args.depth - Current recursion depth (prevents infinite loops)
28
+ * @returns Collated example value matching the schema structure, or undefined if no examples
29
+ *
30
+ * @throws {Error} When recursion depth exceeds 15 levels (prevents stack overflow)
31
+ *
32
+ * @example Basic schema examples
33
+ * ```typescript
34
+ * import { collateExamples } from '@skmtc/core';
35
+ *
36
+ * // String schema with example
37
+ * const stringSchema = new OasString({ example: 'john.doe@example.com' });
38
+ * const example = collateExamples({ objectSchema: stringSchema, depth: 0 });
39
+ * console.log(example); // 'john.doe@example.com'
40
+ *
41
+ * // Number schema with example
42
+ * const numberSchema = new OasNumber({ example: 42 });
43
+ * const numExample = collateExamples({ objectSchema: numberSchema, depth: 0 });
44
+ * console.log(numExample); // 42
45
+ * ```
46
+ *
47
+ * @example Object schema examples
48
+ * ```typescript
49
+ * // Object schema with nested properties
50
+ * const userSchema = new OasObject({
51
+ * properties: {
52
+ * id: new OasInteger({ example: 123 }),
53
+ * name: new OasString({ example: 'John Doe' }),
54
+ * email: new OasString({ example: 'john@example.com' }),
55
+ * age: new OasInteger({ example: 30 })
56
+ * }
57
+ * });
58
+ *
59
+ * const userExample = collateExamples({ objectSchema: userSchema, depth: 0 });
60
+ * console.log(userExample);
61
+ * // {
62
+ * // id: 123,
63
+ * // name: 'John Doe',
64
+ * // email: 'john@example.com',
65
+ * // age: 30
66
+ * // }
67
+ * ```
68
+ *
69
+ * @example Array schema examples
70
+ * ```typescript
71
+ * // Array of objects
72
+ * const usersArraySchema = new OasArray({
73
+ * items: new OasObject({
74
+ * properties: {
75
+ * id: new OasInteger({ example: 1 }),
76
+ * name: new OasString({ example: 'Jane Smith' })
77
+ * }
78
+ * })
79
+ * });
80
+ *
81
+ * const arrayExample = collateExamples({ objectSchema: usersArraySchema, depth: 0 });
82
+ * console.log(arrayExample);
83
+ * // [
84
+ * // {
85
+ * // id: 1,
86
+ * // name: 'Jane Smith'
87
+ * // }
88
+ * // ]
89
+ * ```
90
+ *
91
+ * @example Union schema examples
92
+ * ```typescript
93
+ * // Union of string and number
94
+ * const unionSchema = new OasUnion({
95
+ * members: [
96
+ * new OasString({ example: 'text-value' }),
97
+ * new OasNumber({ example: 99 })
98
+ * ]
99
+ * });
100
+ *
101
+ * const unionExample = collateExamples({ objectSchema: unionSchema, depth: 0 });
102
+ * console.log(unionExample); // 'text-value' (first member with example)
103
+ * ```
104
+ *
105
+ * @example Reference resolution
106
+ * ```typescript
107
+ * // Schema with reference to another schema
108
+ * const addressRef = new OasRef({
109
+ * $ref: '#/components/schemas/Address',
110
+ * resolve: () => new OasObject({
111
+ * properties: {
112
+ * street: new OasString({ example: '123 Main St' }),
113
+ * city: new OasString({ example: 'Springfield' })
114
+ * }
115
+ * })
116
+ * });
117
+ *
118
+ * const refExample = collateExamples({ objectSchema: addressRef, depth: 0 });
119
+ * console.log(refExample);
120
+ * // {
121
+ * // street: '123 Main St',
122
+ * // city: 'Springfield'
123
+ * // }
124
+ * ```
125
+ *
126
+ * @example Depth limiting and error handling
127
+ * ```typescript
128
+ * // Deep nesting detection
129
+ * try {
130
+ * const deepExample = collateExamples({ objectSchema: someSchema, depth: 16 });
131
+ * } catch (error) {
132
+ * console.error('Depth limit exceeded:', error.message); // 'Depth limit reached'
133
+ * }
134
+ *
135
+ * // Handling missing schemas
136
+ * const emptyExample = collateExamples({ objectSchema: undefined, depth: 0 });
137
+ * console.log(emptyExample); // undefined
138
+ * ```
139
+ *
140
+ * @example Using in API documentation generation
141
+ * ```typescript
142
+ * class ApiDocGenerator {
143
+ * generateExampleResponse(responseSchema: OasSchema) {
144
+ * const example = collateExamples({ objectSchema: responseSchema, depth: 0 });
145
+ *
146
+ * if (example) {
147
+ * return {
148
+ * description: 'Example response',
149
+ * value: example
150
+ * };
151
+ * }
152
+ *
153
+ * return { description: 'No example available' };
154
+ * }
155
+ * }
156
+ * ```
157
+ */
8
158
  export declare const collateExamples: ({ objectSchema, depth }: CollatedExampleArgs) => unknown;
9
159
  export {};
10
160
  //# sourceMappingURL=collateExamples.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collateExamples.d.ts","sourceRoot":"","sources":["../../src/helpers/collateExamples.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,KAAK,mBAAmB,GAAG;IACzB,YAAY,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;IACtD,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,yBAAyB,mBAAmB,KAAG,OAwE9E,CAAA"}
1
+ {"version":3,"file":"collateExamples.d.ts","sourceRoot":"","sources":["../../src/helpers/collateExamples.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD;;GAEG;AACH,KAAK,mBAAmB,GAAG;IACzB,+DAA+D;IAC/D,YAAY,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;IACtD,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgJG;AACH,eAAO,MAAM,eAAe,GAAI,yBAAyB,mBAAmB,KAAG,OAwE9E,CAAA"}
@@ -4,6 +4,151 @@ exports.collateExamples = void 0;
4
4
  require("../_dnt.polyfills.js");
5
5
  const ts_pattern_1 = require("ts-pattern");
6
6
  const isEmpty_js_1 = require("./isEmpty.js");
7
+ /**
8
+ * Recursively collates and builds example values from OpenAPI schemas.
9
+ *
10
+ * This function traverses OpenAPI schema structures and generates comprehensive
11
+ * example values based on the schema definitions and any explicit examples provided.
12
+ * It handles complex nested structures including objects, arrays, unions, and
13
+ * references while preventing infinite recursion through depth limiting.
14
+ *
15
+ * The function prioritizes explicit examples when available and falls back to
16
+ * generating examples from nested schemas. It's particularly useful for creating
17
+ * realistic test data, API documentation examples, and mock responses.
18
+ *
19
+ * @param args - Configuration for example collation
20
+ * @param args.objectSchema - The schema to extract examples from
21
+ * @param args.depth - Current recursion depth (prevents infinite loops)
22
+ * @returns Collated example value matching the schema structure, or undefined if no examples
23
+ *
24
+ * @throws {Error} When recursion depth exceeds 15 levels (prevents stack overflow)
25
+ *
26
+ * @example Basic schema examples
27
+ * ```typescript
28
+ * import { collateExamples } from '@skmtc/core';
29
+ *
30
+ * // String schema with example
31
+ * const stringSchema = new OasString({ example: 'john.doe@example.com' });
32
+ * const example = collateExamples({ objectSchema: stringSchema, depth: 0 });
33
+ * console.log(example); // 'john.doe@example.com'
34
+ *
35
+ * // Number schema with example
36
+ * const numberSchema = new OasNumber({ example: 42 });
37
+ * const numExample = collateExamples({ objectSchema: numberSchema, depth: 0 });
38
+ * console.log(numExample); // 42
39
+ * ```
40
+ *
41
+ * @example Object schema examples
42
+ * ```typescript
43
+ * // Object schema with nested properties
44
+ * const userSchema = new OasObject({
45
+ * properties: {
46
+ * id: new OasInteger({ example: 123 }),
47
+ * name: new OasString({ example: 'John Doe' }),
48
+ * email: new OasString({ example: 'john@example.com' }),
49
+ * age: new OasInteger({ example: 30 })
50
+ * }
51
+ * });
52
+ *
53
+ * const userExample = collateExamples({ objectSchema: userSchema, depth: 0 });
54
+ * console.log(userExample);
55
+ * // {
56
+ * // id: 123,
57
+ * // name: 'John Doe',
58
+ * // email: 'john@example.com',
59
+ * // age: 30
60
+ * // }
61
+ * ```
62
+ *
63
+ * @example Array schema examples
64
+ * ```typescript
65
+ * // Array of objects
66
+ * const usersArraySchema = new OasArray({
67
+ * items: new OasObject({
68
+ * properties: {
69
+ * id: new OasInteger({ example: 1 }),
70
+ * name: new OasString({ example: 'Jane Smith' })
71
+ * }
72
+ * })
73
+ * });
74
+ *
75
+ * const arrayExample = collateExamples({ objectSchema: usersArraySchema, depth: 0 });
76
+ * console.log(arrayExample);
77
+ * // [
78
+ * // {
79
+ * // id: 1,
80
+ * // name: 'Jane Smith'
81
+ * // }
82
+ * // ]
83
+ * ```
84
+ *
85
+ * @example Union schema examples
86
+ * ```typescript
87
+ * // Union of string and number
88
+ * const unionSchema = new OasUnion({
89
+ * members: [
90
+ * new OasString({ example: 'text-value' }),
91
+ * new OasNumber({ example: 99 })
92
+ * ]
93
+ * });
94
+ *
95
+ * const unionExample = collateExamples({ objectSchema: unionSchema, depth: 0 });
96
+ * console.log(unionExample); // 'text-value' (first member with example)
97
+ * ```
98
+ *
99
+ * @example Reference resolution
100
+ * ```typescript
101
+ * // Schema with reference to another schema
102
+ * const addressRef = new OasRef({
103
+ * $ref: '#/components/schemas/Address',
104
+ * resolve: () => new OasObject({
105
+ * properties: {
106
+ * street: new OasString({ example: '123 Main St' }),
107
+ * city: new OasString({ example: 'Springfield' })
108
+ * }
109
+ * })
110
+ * });
111
+ *
112
+ * const refExample = collateExamples({ objectSchema: addressRef, depth: 0 });
113
+ * console.log(refExample);
114
+ * // {
115
+ * // street: '123 Main St',
116
+ * // city: 'Springfield'
117
+ * // }
118
+ * ```
119
+ *
120
+ * @example Depth limiting and error handling
121
+ * ```typescript
122
+ * // Deep nesting detection
123
+ * try {
124
+ * const deepExample = collateExamples({ objectSchema: someSchema, depth: 16 });
125
+ * } catch (error) {
126
+ * console.error('Depth limit exceeded:', error.message); // 'Depth limit reached'
127
+ * }
128
+ *
129
+ * // Handling missing schemas
130
+ * const emptyExample = collateExamples({ objectSchema: undefined, depth: 0 });
131
+ * console.log(emptyExample); // undefined
132
+ * ```
133
+ *
134
+ * @example Using in API documentation generation
135
+ * ```typescript
136
+ * class ApiDocGenerator {
137
+ * generateExampleResponse(responseSchema: OasSchema) {
138
+ * const example = collateExamples({ objectSchema: responseSchema, depth: 0 });
139
+ *
140
+ * if (example) {
141
+ * return {
142
+ * description: 'Example response',
143
+ * value: example
144
+ * };
145
+ * }
146
+ *
147
+ * return { description: 'No example available' };
148
+ * }
149
+ * }
150
+ * ```
151
+ */
7
152
  const collateExamples = ({ objectSchema, depth }) => {
8
153
  if (!objectSchema) {
9
154
  return undefined;
@@ -1,3 +1,98 @@
1
+ /**
2
+ * Formats a number using locale-specific formatting without decimal places.
3
+ *
4
+ * This utility function formats numbers according to locale conventions,
5
+ * adding thousand separators and other locale-specific number formatting
6
+ * while ensuring the output contains no fractional digits. It's useful
7
+ * for displaying counts, statistics, or other whole numbers in a
8
+ * human-readable format.
9
+ *
10
+ * @param value - The number to format
11
+ * @param locales - The locale(s) to use for formatting (defaults to 'en-US')
12
+ * @returns The formatted number as a string with locale-appropriate thousand separators
13
+ *
14
+ * @example Basic formatting with default locale (en-US)
15
+ * ```typescript
16
+ * import { formatNumber } from '@skmtc/core';
17
+ *
18
+ * console.log(formatNumber(1234)); // '1,234'
19
+ * console.log(formatNumber(1234567)); // '1,234,567'
20
+ * console.log(formatNumber(42)); // '42'
21
+ * console.log(formatNumber(0)); // '0'
22
+ * ```
23
+ *
24
+ * @example Formatting with different locales
25
+ * ```typescript
26
+ * const bigNumber = 1234567;
27
+ *
28
+ * console.log(formatNumber(bigNumber, 'en-US')); // '1,234,567'
29
+ * console.log(formatNumber(bigNumber, 'de-DE')); // '1.234.567'
30
+ * console.log(formatNumber(bigNumber, 'fr-FR')); // '1 234 567'
31
+ * console.log(formatNumber(bigNumber, 'en-IN')); // '12,34,567'
32
+ * ```
33
+ *
34
+ * @example Formatting decimal numbers (fractional part removed)
35
+ * ```typescript
36
+ * // The function always rounds to whole numbers
37
+ * console.log(formatNumber(1234.56)); // '1,235' (rounded)
38
+ * console.log(formatNumber(999.99)); // '1,000' (rounded)
39
+ * console.log(formatNumber(1000.1)); // '1,000' (rounded)
40
+ * console.log(formatNumber(1000.0)); // '1,000'
41
+ * ```
42
+ *
43
+ * @example Usage in reporting and statistics
44
+ * ```typescript
45
+ * class StatsReporter {
46
+ * generateReport(stats: {
47
+ * totalFiles: number;
48
+ * linesGenerated: number;
49
+ * errors: number;
50
+ * }) {
51
+ * return `
52
+ * Generation Report:
53
+ * - Files generated: ${formatNumber(stats.totalFiles)}
54
+ * - Lines of code: ${formatNumber(stats.linesGenerated)}
55
+ * - Errors encountered: ${formatNumber(stats.errors)}
56
+ * `.trim();
57
+ * }
58
+ * }
59
+ *
60
+ * const reporter = new StatsReporter();
61
+ * const report = reporter.generateReport({
62
+ * totalFiles: 1234,
63
+ * linesGenerated: 567890,
64
+ * errors: 5
65
+ * });
66
+ *
67
+ * console.log(report);
68
+ * // Generation Report:
69
+ * // - Files generated: 1,234
70
+ * // - Lines of code: 567,890
71
+ * // - Errors encountered: 5
72
+ * ```
73
+ *
74
+ * @example International number formatting
75
+ * ```typescript
76
+ * const count = 50000;
77
+ *
78
+ * // Different regions format numbers differently
79
+ * const formats = [
80
+ * { locale: 'en-US', label: 'US English' },
81
+ * { locale: 'de-DE', label: 'German' },
82
+ * { locale: 'fr-FR', label: 'French' },
83
+ * { locale: 'ja-JP', label: 'Japanese' }
84
+ * ];
85
+ *
86
+ * formats.forEach(({ locale, label }) => {
87
+ * console.log(`${label}: ${formatNumber(count, locale)}`);
88
+ * });
89
+ *
90
+ * // US English: 50,000
91
+ * // German: 50.000
92
+ * // French: 50 000
93
+ * // Japanese: 50,000
94
+ * ```
95
+ */
1
96
  import "../_dnt.polyfills.js";
2
97
  export declare const formatNumber: (value: number, locales?: Intl.LocalesArgument) => string;
3
98
  //# sourceMappingURL=formatNumber.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatNumber.d.ts","sourceRoot":"","sources":["../../src/helpers/formatNumber.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,EAAE,UAAS,IAAI,CAAC,eAAyB,KAAG,MAKrF,CAAA"}
1
+ {"version":3,"file":"formatNumber.d.ts","sourceRoot":"","sources":["../../src/helpers/formatNumber.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8FG;AACH,OAAO,sBAAsB,CAAC;AAE9B,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,EAAE,UAAS,IAAI,CAAC,eAAyB,KAAG,MAKrF,CAAA"}
@@ -1,6 +1,101 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatNumber = void 0;
4
+ /**
5
+ * Formats a number using locale-specific formatting without decimal places.
6
+ *
7
+ * This utility function formats numbers according to locale conventions,
8
+ * adding thousand separators and other locale-specific number formatting
9
+ * while ensuring the output contains no fractional digits. It's useful
10
+ * for displaying counts, statistics, or other whole numbers in a
11
+ * human-readable format.
12
+ *
13
+ * @param value - The number to format
14
+ * @param locales - The locale(s) to use for formatting (defaults to 'en-US')
15
+ * @returns The formatted number as a string with locale-appropriate thousand separators
16
+ *
17
+ * @example Basic formatting with default locale (en-US)
18
+ * ```typescript
19
+ * import { formatNumber } from '@skmtc/core';
20
+ *
21
+ * console.log(formatNumber(1234)); // '1,234'
22
+ * console.log(formatNumber(1234567)); // '1,234,567'
23
+ * console.log(formatNumber(42)); // '42'
24
+ * console.log(formatNumber(0)); // '0'
25
+ * ```
26
+ *
27
+ * @example Formatting with different locales
28
+ * ```typescript
29
+ * const bigNumber = 1234567;
30
+ *
31
+ * console.log(formatNumber(bigNumber, 'en-US')); // '1,234,567'
32
+ * console.log(formatNumber(bigNumber, 'de-DE')); // '1.234.567'
33
+ * console.log(formatNumber(bigNumber, 'fr-FR')); // '1 234 567'
34
+ * console.log(formatNumber(bigNumber, 'en-IN')); // '12,34,567'
35
+ * ```
36
+ *
37
+ * @example Formatting decimal numbers (fractional part removed)
38
+ * ```typescript
39
+ * // The function always rounds to whole numbers
40
+ * console.log(formatNumber(1234.56)); // '1,235' (rounded)
41
+ * console.log(formatNumber(999.99)); // '1,000' (rounded)
42
+ * console.log(formatNumber(1000.1)); // '1,000' (rounded)
43
+ * console.log(formatNumber(1000.0)); // '1,000'
44
+ * ```
45
+ *
46
+ * @example Usage in reporting and statistics
47
+ * ```typescript
48
+ * class StatsReporter {
49
+ * generateReport(stats: {
50
+ * totalFiles: number;
51
+ * linesGenerated: number;
52
+ * errors: number;
53
+ * }) {
54
+ * return `
55
+ * Generation Report:
56
+ * - Files generated: ${formatNumber(stats.totalFiles)}
57
+ * - Lines of code: ${formatNumber(stats.linesGenerated)}
58
+ * - Errors encountered: ${formatNumber(stats.errors)}
59
+ * `.trim();
60
+ * }
61
+ * }
62
+ *
63
+ * const reporter = new StatsReporter();
64
+ * const report = reporter.generateReport({
65
+ * totalFiles: 1234,
66
+ * linesGenerated: 567890,
67
+ * errors: 5
68
+ * });
69
+ *
70
+ * console.log(report);
71
+ * // Generation Report:
72
+ * // - Files generated: 1,234
73
+ * // - Lines of code: 567,890
74
+ * // - Errors encountered: 5
75
+ * ```
76
+ *
77
+ * @example International number formatting
78
+ * ```typescript
79
+ * const count = 50000;
80
+ *
81
+ * // Different regions format numbers differently
82
+ * const formats = [
83
+ * { locale: 'en-US', label: 'US English' },
84
+ * { locale: 'de-DE', label: 'German' },
85
+ * { locale: 'fr-FR', label: 'French' },
86
+ * { locale: 'ja-JP', label: 'Japanese' }
87
+ * ];
88
+ *
89
+ * formats.forEach(({ locale, label }) => {
90
+ * console.log(`${label}: ${formatNumber(count, locale)}`);
91
+ * });
92
+ *
93
+ * // US English: 50,000
94
+ * // German: 50.000
95
+ * // French: 50 000
96
+ * // Japanese: 50,000
97
+ * ```
98
+ */
4
99
  require("../_dnt.polyfills.js");
5
100
  const formatNumber = (value, locales = 'en-US') => {
6
101
  return value.toLocaleString(locales, {