@augment-vir/common 30.0.0 → 30.0.2

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 (174) hide show
  1. package/README.md +11 -0
  2. package/dist/augments/array/array-map.d.ts +29 -1
  3. package/dist/augments/array/array-map.js +29 -1
  4. package/dist/augments/array/array-to-object.d.ts +27 -9
  5. package/dist/augments/array/array-to-object.js +96 -12
  6. package/dist/augments/array/awaited/awaited-filter.d.ts +29 -0
  7. package/dist/augments/array/awaited/awaited-filter.js +29 -0
  8. package/dist/augments/array/awaited/awaited-for-each.d.ts +28 -3
  9. package/dist/augments/array/awaited/awaited-for-each.js +28 -3
  10. package/dist/augments/array/awaited/awaited-map.d.ts +32 -0
  11. package/dist/augments/array/awaited/awaited-map.js +32 -0
  12. package/dist/augments/array/filter.d.ts +29 -0
  13. package/dist/augments/array/filter.js +61 -0
  14. package/dist/augments/array/remove-duplicates.d.ts +60 -1
  15. package/dist/augments/array/remove-duplicates.js +61 -2
  16. package/dist/augments/array/repeat-array.d.ts +22 -0
  17. package/dist/augments/array/repeat-array.js +22 -0
  18. package/dist/augments/array/shuffle-array.d.ts +8 -1
  19. package/dist/augments/array/shuffle-array.js +8 -1
  20. package/dist/augments/array/string-array.d.ts +8 -0
  21. package/dist/augments/array/string-array.js +8 -0
  22. package/dist/augments/enum/enum-value-check.d.ts +30 -0
  23. package/dist/augments/enum/enum-value-check.js +30 -0
  24. package/dist/augments/error/combine-errors.d.ts +24 -3
  25. package/dist/augments/error/combine-errors.js +26 -4
  26. package/dist/augments/function/call-asynchronously.d.ts +19 -0
  27. package/dist/augments/function/call-asynchronously.js +19 -0
  28. package/dist/augments/function/call-with-retries.d.ts +23 -3
  29. package/dist/augments/function/call-with-retries.js +23 -0
  30. package/dist/augments/function/debounce.d.ts +71 -4
  31. package/dist/augments/function/debounce.js +66 -4
  32. package/dist/augments/function/execution-duration.d.ts +17 -5
  33. package/dist/augments/function/execution-duration.js +16 -3
  34. package/dist/augments/function/if-truthy.d.ts +28 -0
  35. package/dist/augments/function/if-truthy.js +35 -0
  36. package/dist/augments/function/wrap-in-try.d.ts +12 -4
  37. package/dist/augments/function/wrap-in-try.js +64 -0
  38. package/dist/augments/json/append-json.d.ts +3 -3
  39. package/dist/augments/json/append-json.js +33 -0
  40. package/dist/augments/json/copy-through-json.d.ts +32 -1
  41. package/dist/augments/json/copy-through-json.js +32 -1
  42. package/dist/augments/json/json-compatible.d.ts +37 -9
  43. package/dist/augments/json/jsonify.d.ts +30 -1
  44. package/dist/augments/json/jsonify.js +31 -2
  45. package/dist/augments/log/log-colors.d.ts +41 -0
  46. package/dist/augments/log/log-colors.js +43 -2
  47. package/dist/augments/log/log-string.d.ts +21 -0
  48. package/dist/augments/log/log-string.js +9 -2
  49. package/dist/augments/log/log-writer.d.ts +22 -0
  50. package/dist/augments/log/log.d.ts +44 -1
  51. package/dist/augments/log/log.js +46 -3
  52. package/dist/augments/log/logger.d.ts +49 -0
  53. package/dist/augments/log/logger.js +21 -0
  54. package/dist/augments/number/clamp.d.ts +13 -2
  55. package/dist/augments/number/clamp.js +12 -1
  56. package/dist/augments/number/coords.d.ts +6 -2
  57. package/dist/augments/number/digit.d.ts +7 -0
  58. package/dist/augments/number/dimensions.d.ts +6 -2
  59. package/dist/augments/number/min-max.d.ts +9 -2
  60. package/dist/augments/number/min-max.js +4 -2
  61. package/dist/augments/number/number-conversion.d.ts +9 -3
  62. package/dist/augments/number/number-conversion.js +10 -4
  63. package/dist/augments/number/round.d.ts +19 -0
  64. package/dist/augments/number/round.js +19 -0
  65. package/dist/augments/number/scientific.d.ts +18 -1
  66. package/dist/augments/number/scientific.js +18 -1
  67. package/dist/augments/number/truncate-number.d.ts +24 -3
  68. package/dist/augments/number/truncate-number.js +28 -8
  69. package/dist/augments/number/wrap-number.d.ts +9 -3
  70. package/dist/augments/number/wrap-number.js +8 -2
  71. package/dist/augments/object/diff.d.ts +27 -5
  72. package/dist/augments/object/diff.js +20 -4
  73. package/dist/augments/object/empty.d.ts +7 -1
  74. package/dist/augments/object/get-or-set.d.ts +6 -27
  75. package/dist/augments/object/get-or-set.js +66 -4
  76. package/dist/augments/object/key-count.d.ts +4 -0
  77. package/dist/augments/object/map-entries.js +23 -0
  78. package/dist/augments/object/map-enum.d.ts +7 -0
  79. package/dist/augments/object/map-enum.js +24 -0
  80. package/dist/augments/object/map-values.d.ts +25 -13
  81. package/dist/augments/object/map-values.js +29 -21
  82. package/dist/augments/object/merge-deep.d.ts +4 -0
  83. package/dist/augments/object/merge-deep.js +4 -0
  84. package/dist/augments/object/merge-defined-properties.d.ts +13 -0
  85. package/dist/augments/object/merge-defined-properties.js +13 -0
  86. package/dist/augments/object/merge-property-arrays.d.ts +28 -0
  87. package/dist/augments/object/merge-property-arrays.js +28 -0
  88. package/dist/augments/object/object-entries.d.ts +27 -0
  89. package/dist/augments/object/object-entries.js +27 -0
  90. package/dist/augments/object/object-filter.d.ts +20 -0
  91. package/dist/augments/object/object-filter.js +20 -0
  92. package/dist/augments/object/object-keys.d.ts +32 -0
  93. package/dist/augments/object/object-keys.js +32 -0
  94. package/dist/augments/object/object-values.d.ts +9 -0
  95. package/dist/augments/object/object-values.js +9 -0
  96. package/dist/augments/path/esm-path.d.ts +26 -0
  97. package/dist/augments/path/esm-path.js +31 -0
  98. package/dist/augments/prisma/base-prisma-types.d.ts +38 -0
  99. package/dist/augments/prisma/prisma-basic-model.d.ts +29 -0
  100. package/dist/augments/prisma/prisma-basic-model.js +1 -0
  101. package/dist/augments/prisma/prisma-full-model.d.ts +37 -0
  102. package/dist/augments/prisma/prisma-full-model.js +1 -0
  103. package/dist/augments/prisma/prisma-model-create.d.ts +159 -0
  104. package/dist/augments/prisma/prisma-model-create.js +58 -0
  105. package/dist/augments/prisma/prisma-model-name.d.ts +18 -0
  106. package/dist/augments/prisma/prisma-model-name.js +1 -0
  107. package/dist/augments/promise/timed-promise.d.ts +15 -0
  108. package/dist/augments/promise/timed-promise.js +15 -0
  109. package/dist/augments/random/random-boolean.d.ts +6 -0
  110. package/dist/augments/random/random-boolean.js +6 -0
  111. package/dist/augments/random/random-integer.d.ts +3 -1
  112. package/dist/augments/random/random-integer.js +3 -1
  113. package/dist/augments/random/random-string.d.ts +6 -2
  114. package/dist/augments/random/random-string.js +6 -2
  115. package/dist/augments/regexp/match.d.ts +10 -0
  116. package/dist/augments/regexp/match.js +13 -0
  117. package/dist/augments/regexp/regexp-flags.d.ts +56 -3
  118. package/dist/augments/regexp/regexp-flags.js +71 -14
  119. package/dist/augments/regexp/regexp-string.d.ts +4 -0
  120. package/dist/augments/regexp/regexp-string.js +5 -1
  121. package/dist/augments/selection-set/select-collapsed.d.ts +46 -3
  122. package/dist/augments/selection-set/select-collapsed.js +40 -2
  123. package/dist/augments/selection-set/select-from.d.ts +47 -2
  124. package/dist/augments/selection-set/select-from.js +48 -1
  125. package/dist/augments/selection-set/selection-set.d.ts +26 -7
  126. package/dist/augments/selection-set/selection-set.js +1 -4
  127. package/dist/augments/string/casing/capitalization.d.ts +15 -1
  128. package/dist/augments/string/casing/capitalization.js +14 -0
  129. package/dist/augments/string/casing/casing.d.ts +53 -7
  130. package/dist/augments/string/casing/casing.js +36 -11
  131. package/dist/augments/string/casing/kebab-and-camel.d.ts +14 -0
  132. package/dist/augments/string/casing/kebab-and-camel.js +20 -5
  133. package/dist/augments/string/comma.d.ts +26 -0
  134. package/dist/augments/string/{commas.js → comma.js} +21 -2
  135. package/dist/augments/string/join.d.ts +15 -4
  136. package/dist/augments/string/join.js +15 -4
  137. package/dist/augments/string/prefix.d.ts +6 -0
  138. package/dist/augments/string/prefix.js +4 -0
  139. package/dist/augments/string/remove-duplicate-characters.d.ts +17 -0
  140. package/dist/augments/string/remove-duplicate-characters.js +22 -0
  141. package/dist/augments/string/replace.d.ts +17 -0
  142. package/dist/augments/string/replace.js +17 -0
  143. package/dist/augments/string/split.d.ts +29 -2
  144. package/dist/augments/string/split.js +32 -7
  145. package/dist/augments/string/substring-index.d.ts +11 -5
  146. package/dist/augments/string/substring-index.js +12 -3
  147. package/dist/augments/string/suffix.d.ts +22 -0
  148. package/dist/augments/string/suffix.js +16 -0
  149. package/dist/augments/string/white-space.d.ts +8 -1
  150. package/dist/augments/string/white-space.js +8 -1
  151. package/dist/augments/string/wrap-string.d.ts +15 -0
  152. package/dist/augments/string/wrap-string.js +15 -0
  153. package/dist/augments/type/ensure-type.d.ts +4 -0
  154. package/dist/augments/type/ensure-type.js +4 -0
  155. package/dist/augments/type/readonly.d.ts +7 -0
  156. package/dist/augments/type/readonly.js +7 -0
  157. package/dist/augments/type/type-recursion.d.ts +93 -1
  158. package/dist/augments/type/union.d.ts +1 -0
  159. package/dist/augments/type/union.js +1 -0
  160. package/dist/augments/type/void-type.d.ts +6 -2
  161. package/dist/augments/type/writable.d.ts +7 -0
  162. package/dist/augments/type/writable.js +7 -0
  163. package/dist/index.d.ts +11 -5
  164. package/dist/index.js +11 -5
  165. package/package.json +19 -9
  166. package/dist/augments/boolean/if-truthy.d.ts +0 -2
  167. package/dist/augments/boolean/if-truthy.js +0 -9
  168. package/dist/augments/file/esm-path.d.ts +0 -4
  169. package/dist/augments/file/esm-path.js +0 -8
  170. package/dist/augments/prisma/prisma-models.d.ts +0 -106
  171. package/dist/augments/regexp/safe-match.d.ts +0 -1
  172. package/dist/augments/regexp/safe-match.js +0 -4
  173. package/dist/augments/string/commas.d.ts +0 -7
  174. /package/dist/augments/prisma/{prisma-models.js → base-prisma-types.js} +0 -0
@@ -2,9 +2,52 @@ import { type PartialWithUndefined } from '@augment-vir/core';
2
2
  import { LoggerOptions } from './log-string.js';
3
3
  import { LogWriters } from './log-writer.js';
4
4
  import { type Logger } from './logger.js';
5
+ /**
6
+ * Default implementation of {@link LogWriters} that is dependent on the current runtime environment.
7
+ *
8
+ * @category Log : Util
9
+ * @category Package : @augment-vir/common
10
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
+ */
5
12
  export declare const defaultLogWriters: LogWriters;
13
+ /**
14
+ * The default `log`. Use this in place of `console` methods for styled outputs in both Node.js and
15
+ * the browser.
16
+ *
17
+ * @category Log
18
+ * @category Package : @augment-vir/common
19
+ * @example
20
+ *
21
+ * ```ts
22
+ * import {log} from '@augment-vir/common';
23
+ *
24
+ * log.info('hi');
25
+ * log.error('failure');
26
+ * ```
27
+ *
28
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
29
+ */
6
30
  export declare const log: Logger;
7
- export declare function createLoggerWithStoredLogs(options?: PartialWithUndefined<LoggerOptions> | undefined): {
31
+ /**
32
+ * Creates a custom logger that doesn't actually log but stores the logs into a object for later
33
+ * usage. This is particularly useful in tests.
34
+ *
35
+ * @category Log
36
+ * @category Package : @augment-vir/common
37
+ * @example
38
+ *
39
+ * ```ts
40
+ * import {createArrayLogger} from '@augment-vir/common';
41
+ *
42
+ * const {log, logs} = createArrayLogger();
43
+ *
44
+ * log.info('hi');
45
+ * // `logs[LogOutputType.Standard]` is now `['hi']`
46
+ * ```
47
+ *
48
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
49
+ */
50
+ export declare function createArrayLogger(options?: PartialWithUndefined<LoggerOptions> | undefined): {
8
51
  log: Logger;
9
52
  logs: {
10
53
  stdout: string[];
@@ -2,6 +2,13 @@ import { isRuntimeEnv, RuntimeEnv } from '@augment-vir/core';
2
2
  import { addPrefix } from '../string/prefix.js';
3
3
  import { LogOutputType } from './log-colors.js';
4
4
  import { createLogger } from './logger.js';
5
+ /**
6
+ * Default implementation of {@link LogWriters} that is dependent on the current runtime environment.
7
+ *
8
+ * @category Log : Util
9
+ * @category Package : @augment-vir/common
10
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
+ */
5
12
  export const defaultLogWriters =
6
13
  /** We calculate coverage in web, so the node code will never run in coverage tests. */
7
14
  /* node:coverage disable */
@@ -24,11 +31,47 @@ isRuntimeEnv(RuntimeEnv.Node)
24
31
  console.log(addPrefix({ value: text, prefix: '%c' }), css);
25
32
  },
26
33
  };
34
+ /**
35
+ * The default `log`. Use this in place of `console` methods for styled outputs in both Node.js and
36
+ * the browser.
37
+ *
38
+ * @category Log
39
+ * @category Package : @augment-vir/common
40
+ * @example
41
+ *
42
+ * ```ts
43
+ * import {log} from '@augment-vir/common';
44
+ *
45
+ * log.info('hi');
46
+ * log.error('failure');
47
+ * ```
48
+ *
49
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
50
+ */
27
51
  export const log = createLogger(defaultLogWriters);
28
- export function createLoggerWithStoredLogs(options) {
52
+ /**
53
+ * Creates a custom logger that doesn't actually log but stores the logs into a object for later
54
+ * usage. This is particularly useful in tests.
55
+ *
56
+ * @category Log
57
+ * @category Package : @augment-vir/common
58
+ * @example
59
+ *
60
+ * ```ts
61
+ * import {createArrayLogger} from '@augment-vir/common';
62
+ *
63
+ * const {log, logs} = createArrayLogger();
64
+ *
65
+ * log.info('hi');
66
+ * // `logs[LogOutputType.Standard]` is now `['hi']`
67
+ * ```
68
+ *
69
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
70
+ */
71
+ export function createArrayLogger(options) {
29
72
  const logs = {
30
- stdout: [],
31
- stderr: [],
73
+ [LogOutputType.Standard]: [],
74
+ [LogOutputType.Error]: [],
32
75
  };
33
76
  const log = createLogger({
34
77
  stderr({ text }) {
@@ -2,10 +2,59 @@ import type { PartialWithUndefined } from '@augment-vir/core';
2
2
  import { LogColorKey } from './log-colors.js';
3
3
  import { type LoggerOptions } from './log-string.js';
4
4
  import { type LogWriters } from './log-writer.js';
5
+ /**
6
+ * The base `log` methods.
7
+ *
8
+ * @category Log : Util
9
+ * @category Package : @augment-vir/common
10
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
+ */
5
12
  export type LoggerLogs = Readonly<Record<LogColorKey, (...args: ReadonlyArray<unknown>) => void>>;
13
+ /**
14
+ * Type for the `log` export.
15
+ *
16
+ * @category Log : Util
17
+ * @category Package : @augment-vir/common
18
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
19
+ */
6
20
  export type Logger = LoggerLogs & {
21
+ /**
22
+ * Only logs if the given condition is `true`.
23
+ *
24
+ * @example
25
+ *
26
+ * ```ts
27
+ * import {log} from '@augment-vir/common';
28
+ *
29
+ * // this will log
30
+ * log.if(true).info('hi');
31
+ * // this will not log
32
+ * log.if(false).info('hi');
33
+ * ```
34
+ */
7
35
  if: (condition: boolean) => LoggerLogs;
8
36
  };
37
+ /**
38
+ * Default implementation of {@link LoggerOptions}.
39
+ *
40
+ * @category Log : Util
41
+ * @category Package : @augment-vir/common
42
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
43
+ */
9
44
  export declare const defaultLoggerOptions: LoggerOptions;
45
+ /**
46
+ * A default {@link Logger} that simply does nothing.
47
+ *
48
+ * @category Log
49
+ * @category Package : @augment-vir/common
50
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
51
+ */
10
52
  export declare const emptyLog: Logger;
53
+ /**
54
+ * Creates a custom {@link Logger}.
55
+ *
56
+ * @category Log
57
+ * @category Package : @augment-vir/common
58
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
59
+ */
11
60
  export declare function createLogger(logWriters: LogWriters, optionsOverride?: PartialWithUndefined<LoggerOptions> | undefined): Logger;
@@ -2,14 +2,35 @@ import { mapEnumToObject } from '../object/map-enum.js';
2
2
  import { mergeDefinedProperties } from '../object/merge-defined-properties.js';
3
3
  import { defaultLogColorConfig, LogColorKey, LogOutputType } from './log-colors.js';
4
4
  import { toLogString } from './log-string.js';
5
+ /**
6
+ * Default implementation of {@link LoggerOptions}.
7
+ *
8
+ * @category Log : Util
9
+ * @category Package : @augment-vir/common
10
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
+ */
5
12
  export const defaultLoggerOptions = {
6
13
  colorConfig: defaultLogColorConfig,
7
14
  omitColors: false,
8
15
  };
16
+ /**
17
+ * A default {@link Logger} that simply does nothing.
18
+ *
19
+ * @category Log
20
+ * @category Package : @augment-vir/common
21
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
22
+ */
9
23
  export const emptyLog = createLogger({
10
24
  [LogOutputType.Error]() { },
11
25
  [LogOutputType.Standard]() { },
12
26
  });
27
+ /**
28
+ * Creates a custom {@link Logger}.
29
+ *
30
+ * @category Log
31
+ * @category Package : @augment-vir/common
32
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
33
+ */
13
34
  export function createLogger(logWriters, optionsOverride) {
14
35
  const options = mergeDefinedProperties(defaultLoggerOptions, optionsOverride);
15
36
  function writeLog(params) {
@@ -2,6 +2,17 @@ import { MinMax } from './min-max.js';
2
2
  /**
3
3
  * Clamp's the given value to within the min and max bounds, inclusive.
4
4
  *
5
- * @category Number:Common
5
+ * @category Number
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {clamp} from '@augment-vir/common';
11
+ *
12
+ * // `result` will be `40`
13
+ * const result = clamp(42, {min: 30, max: 40});
14
+ * ```
15
+ *
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
6
17
  */
7
- export declare function clamp(value: number, { min, max }: MinMax): number;
18
+ export declare function clamp(value: number, { min, max }: Readonly<MinMax>): number;
@@ -1,7 +1,18 @@
1
1
  /**
2
2
  * Clamp's the given value to within the min and max bounds, inclusive.
3
3
  *
4
- * @category Number:Common
4
+ * @category Number
5
+ * @category Package : @augment-vir/common
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * import {clamp} from '@augment-vir/common';
10
+ *
11
+ * // `result` will be `40`
12
+ * const result = clamp(42, {min: 30, max: 40});
13
+ * ```
14
+ *
15
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
5
16
  */
6
17
  export function clamp(value, { min, max }) {
7
18
  return Math.min(Math.max(value, min), max);
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * A simple type for storing 2D coordinates.
3
3
  *
4
- * @category Number:Common
4
+ * @category Number
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
5
7
  */
6
8
  export type Coords = {
7
9
  x: number;
@@ -10,7 +12,9 @@ export type Coords = {
10
12
  /**
11
13
  * A simple type for storing 3D coordinates.
12
14
  *
13
- * @category Number:Common
15
+ * @category Number
16
+ * @category Package : @augment-vir/common
17
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
14
18
  */
15
19
  export type Coords3d = {
16
20
  x: number;
@@ -1 +1,8 @@
1
+ /**
2
+ * A union of all single digits in base 10.
3
+ *
4
+ * @category Number
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
+ */
1
8
  export type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * A simple type for storing 2D dimensions.
3
3
  *
4
- * @category Number:Common
4
+ * @category Number
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
5
7
  */
6
8
  export type Dimensions = {
7
9
  width: number;
@@ -10,7 +12,9 @@ export type Dimensions = {
10
12
  /**
11
13
  * A simple type for storing 3D dimensions.
12
14
  *
13
- * @category Number:Common
15
+ * @category Number
16
+ * @category Package : @augment-vir/common
17
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
14
18
  */
15
19
  export type Dimensions3d = {
16
20
  width: number;
@@ -1,11 +1,18 @@
1
+ /**
2
+ * @category Number
3
+ * @category Package : @augment-vir/common
4
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
5
+ */
1
6
  export type MinMax = {
2
7
  min: number;
3
8
  max: number;
4
9
  };
5
10
  /**
6
11
  * Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
7
- * that is not the case, the returned value is the given min and max values swapped.
12
+ * that is not the case, values are swapped.
8
13
  *
9
- * @category Number:Common
14
+ * @category Number
15
+ * @category Package : @augment-vir/common
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
10
17
  */
11
18
  export declare function ensureMinMax({ min, max }: MinMax): MinMax;
@@ -1,8 +1,10 @@
1
1
  /**
2
2
  * Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
3
- * that is not the case, the returned value is the given min and max values swapped.
3
+ * that is not the case, values are swapped.
4
4
  *
5
- * @category Number:Common
5
+ * @category Number
6
+ * @category Package : @augment-vir/common
7
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
6
8
  */
7
9
  export function ensureMinMax({ min, max }) {
8
10
  if (min > max) {
@@ -2,22 +2,28 @@
2
2
  * Converts the input into a number and returns `NaN` if the conversion fails. This handles more
3
3
  * edge cases than just plain `Number(input)`.
4
4
  *
5
- * @category Number:Common
5
+ * @category Number
6
+ * @category Package : @augment-vir/common
6
7
  * @returns The converted number or `NaN`.
8
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
9
  */
8
10
  export declare function toNumber(input: unknown): number;
9
11
  /**
10
12
  * Converts the input into a number and throws an error if the conversion fails.
11
13
  *
12
- * @category Number:Common
14
+ * @category Number
15
+ * @category Package : @augment-vir/common
13
16
  * @returns The converted number
14
17
  * @throws `TypeError` if the conversion resulted in `NaN`
18
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
15
19
  */
16
20
  export declare function toEnsuredNumber(input: unknown): number;
17
21
  /**
18
22
  * Converts the input into a number and returns `undefined` if the conversion fails.
19
23
  *
20
- * @category Number:Common
24
+ * @category Number
25
+ * @category Package : @augment-vir/common
21
26
  * @returns The converted number or `undefined`.
27
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
22
28
  */
23
29
  export declare function toMaybeNumber(input: unknown): number | undefined;
@@ -1,10 +1,12 @@
1
- import { removeCommas } from '../string/commas.js';
1
+ import { removeCommas } from '../string/comma.js';
2
2
  /**
3
3
  * Converts the input into a number and returns `NaN` if the conversion fails. This handles more
4
4
  * edge cases than just plain `Number(input)`.
5
5
  *
6
- * @category Number:Common
6
+ * @category Number
7
+ * @category Package : @augment-vir/common
7
8
  * @returns The converted number or `NaN`.
9
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
8
10
  */
9
11
  export function toNumber(input) {
10
12
  if (typeof input === 'number') {
@@ -20,9 +22,11 @@ export function toNumber(input) {
20
22
  /**
21
23
  * Converts the input into a number and throws an error if the conversion fails.
22
24
  *
23
- * @category Number:Common
25
+ * @category Number
26
+ * @category Package : @augment-vir/common
24
27
  * @returns The converted number
25
28
  * @throws `TypeError` if the conversion resulted in `NaN`
29
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
26
30
  */
27
31
  export function toEnsuredNumber(input) {
28
32
  const maybeNumber = toMaybeNumber(input);
@@ -36,8 +40,10 @@ export function toEnsuredNumber(input) {
36
40
  /**
37
41
  * Converts the input into a number and returns `undefined` if the conversion fails.
38
42
  *
39
- * @category Number:Common
43
+ * @category Number
44
+ * @category Package : @augment-vir/common
40
45
  * @returns The converted number or `undefined`.
46
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
41
47
  */
42
48
  export function toMaybeNumber(input) {
43
49
  const numeric = toNumber(input);
@@ -1,3 +1,22 @@
1
+ /**
2
+ * Round a value to the given number of decimal digits. If no decimal value is present, no rounding
3
+ * occurs.
4
+ *
5
+ * @category Number
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {round} from '@augment-vir/common';
11
+ *
12
+ * // `result1` is `5.13`
13
+ * const result1 = round(5.125, {digits: 2});
14
+ * // `result2` is `5`
15
+ * const result2 = round(25, {digits: 2});
16
+ * ```
17
+ *
18
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
19
+ */
1
20
  export declare function round(value: number, { digits }: {
2
21
  digits: number;
3
22
  }): number;
@@ -1,3 +1,22 @@
1
+ /**
2
+ * Round a value to the given number of decimal digits. If no decimal value is present, no rounding
3
+ * occurs.
4
+ *
5
+ * @category Number
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {round} from '@augment-vir/common';
11
+ *
12
+ * // `result1` is `5.13`
13
+ * const result1 = round(5.125, {digits: 2});
14
+ * // `result2` is `5`
15
+ * const result2 = round(25, {digits: 2});
16
+ * ```
17
+ *
18
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
19
+ */
1
20
  export function round(value, { digits }) {
2
21
  const digitFactor = Math.pow(10, digits);
3
22
  const multiplied = value * digitFactor;
@@ -1 +1,18 @@
1
- export declare function doesRequireScientificNotation(input: number): boolean;
1
+ /**
2
+ * Determines if the given number is so large that it requires scientific notation (`e`) when
3
+ * represented as a string.
4
+ *
5
+ * @category Number
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {requiresScientificNotation} from '@augment-vir/common';
11
+ *
12
+ * requiresScientificNotation(5); // false
13
+ * requiresScientificNotation(999999999999999999999); // true
14
+ * ```
15
+ *
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
18
+ export declare function requiresScientificNotation(input: number): boolean;
@@ -1,3 +1,20 @@
1
- export function doesRequireScientificNotation(input) {
1
+ /**
2
+ * Determines if the given number is so large that it requires scientific notation (`e`) when
3
+ * represented as a string.
4
+ *
5
+ * @category Number
6
+ * @category Package : @augment-vir/common
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {requiresScientificNotation} from '@augment-vir/common';
11
+ *
12
+ * requiresScientificNotation(5); // false
13
+ * requiresScientificNotation(999999999999999999999); // true
14
+ * ```
15
+ *
16
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
+ */
18
+ export function requiresScientificNotation(input) {
2
19
  return String(input).includes('e');
3
20
  }
@@ -1,8 +1,16 @@
1
1
  /**
2
- * This truncates a number such that is will at a max have 6 characters including suffix, decimal
3
- * point, or comma.
2
+ * The default truncation prefixes for {@link truncateNumber}.
4
3
  *
5
- * Default suffixes are:
4
+ * @category Number
5
+ * @category Package : @augment-vir/common
6
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
7
+ */
8
+ export declare const defaultTruncationSuffixes: readonly ["k", "M", "B", "T", "P", "E", "Z", "Y"];
9
+ /**
10
+ * Truncates a number such that is will at a max have 6 (customizable) characters including suffix,
11
+ * decimal point, or comma.
12
+ *
13
+ * Default suffixes are in {@link defaultTruncationSuffixes}:
6
14
  *
7
15
  * 'k', // thousand
8
16
  * 'M', // million
@@ -12,6 +20,19 @@
12
20
  * 'E', // exa- quintillion
13
21
  * 'Z', // zetta- sextillion
14
22
  * 'Y', // yotta- septillion
23
+ *
24
+ * @category Number
25
+ * @category Package : @augment-vir/common
26
+ * @example
27
+ *
28
+ * ```ts
29
+ * import {truncateNumber} from '@augment-vir/common';
30
+ *
31
+ * // `result` will be `'1M'`
32
+ * const result = truncateNumber(1_000_000);
33
+ * ```
34
+ *
35
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
15
36
  */
16
37
  export declare function truncateNumber(originalValue: Readonly<unknown>, { customSuffixes, maxLength, }?: Partial<{
17
38
  customSuffixes: ReadonlyArray<string> | undefined;
@@ -1,9 +1,16 @@
1
- import { safeMatch } from '../regexp/safe-match.js';
2
- import { addCommasToNumber } from '../string/commas.js';
1
+ import { safeMatch } from '../regexp/match.js';
2
+ import { addCommasToNumber } from '../string/comma.js';
3
3
  import { safeSplit } from '../string/split.js';
4
4
  import { toNumber } from './number-conversion.js';
5
- import { doesRequireScientificNotation } from './scientific.js';
6
- const defaultTruncationSuffixes = [
5
+ import { requiresScientificNotation } from './scientific.js';
6
+ /**
7
+ * The default truncation prefixes for {@link truncateNumber}.
8
+ *
9
+ * @category Number
10
+ * @category Package : @augment-vir/common
11
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
12
+ */
13
+ export const defaultTruncationSuffixes = [
7
14
  'k', // thousand
8
15
  'M', // million
9
16
  'B', // billion
@@ -119,10 +126,10 @@ function handleSmallNumbers(numberAsString, maxLength) {
119
126
  return undefined;
120
127
  }
121
128
  /**
122
- * This truncates a number such that is will at a max have 6 characters including suffix, decimal
123
- * point, or comma.
129
+ * Truncates a number such that is will at a max have 6 (customizable) characters including suffix,
130
+ * decimal point, or comma.
124
131
  *
125
- * Default suffixes are:
132
+ * Default suffixes are in {@link defaultTruncationSuffixes}:
126
133
  *
127
134
  * 'k', // thousand
128
135
  * 'M', // million
@@ -132,6 +139,19 @@ function handleSmallNumbers(numberAsString, maxLength) {
132
139
  * 'E', // exa- quintillion
133
140
  * 'Z', // zetta- sextillion
134
141
  * 'Y', // yotta- septillion
142
+ *
143
+ * @category Number
144
+ * @category Package : @augment-vir/common
145
+ * @example
146
+ *
147
+ * ```ts
148
+ * import {truncateNumber} from '@augment-vir/common';
149
+ *
150
+ * // `result` will be `'1M'`
151
+ * const result = truncateNumber(1_000_000);
152
+ * ```
153
+ *
154
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
135
155
  */
136
156
  export function truncateNumber(originalValue, { customSuffixes = defaultTruncationSuffixes, maxLength = 6, } = {}) {
137
157
  const inputNumber = toNumber(originalValue);
@@ -140,7 +160,7 @@ export function truncateNumber(originalValue, { customSuffixes = defaultTruncati
140
160
  return String(inputNumber);
141
161
  }
142
162
  // handle too big or too small edge cases
143
- if (doesRequireScientificNotation(inputNumber)) {
163
+ if (requiresScientificNotation(inputNumber)) {
144
164
  return truncateScientificNotation({ input: inputNumber, maxLength });
145
165
  }
146
166
  const numberAsString = String(inputNumber);
@@ -1,13 +1,19 @@
1
1
  import { MinMax } from './min-max.js';
2
2
  /**
3
3
  * If the given value is outside the given min/max bounds, instead of clamping the number (as the
4
- * `clamp` function does), this function wraps the value around to the next bound.
4
+ * {@link clamp} function does), this function wraps the value around to the next bound (inclusive).
5
5
  *
6
- * @category Number:Common
6
+ * @category Number
7
+ * @category Package : @augment-vir/common
7
8
  * @example
8
9
  *
9
10
  * ```ts
11
+ * import {wrapNumber} from '@augment-vir/common';
12
+ *
10
13
  * wrapNumber({min: 0, max: 100, value: 101}); // 0
14
+ * wrapNumber({min: 0, max: 100, value: -1}); // 100
11
15
  * ```
16
+ *
17
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
12
18
  */
13
- export declare function wrapNumber(value: number, minMax: MinMax): number;
19
+ export declare function wrapNumber(value: number, minMax: Readonly<MinMax>): number;
@@ -1,14 +1,20 @@
1
1
  import { ensureMinMax } from './min-max.js';
2
2
  /**
3
3
  * If the given value is outside the given min/max bounds, instead of clamping the number (as the
4
- * `clamp` function does), this function wraps the value around to the next bound.
4
+ * {@link clamp} function does), this function wraps the value around to the next bound (inclusive).
5
5
  *
6
- * @category Number:Common
6
+ * @category Number
7
+ * @category Package : @augment-vir/common
7
8
  * @example
8
9
  *
9
10
  * ```ts
11
+ * import {wrapNumber} from '@augment-vir/common';
12
+ *
10
13
  * wrapNumber({min: 0, max: 100, value: 101}); // 0
14
+ * wrapNumber({min: 0, max: 100, value: -1}); // 100
11
15
  * ```
16
+ *
17
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
12
18
  */
13
19
  export function wrapNumber(value, minMax) {
14
20
  const { min, max } = ensureMinMax(minMax);