@augment-vir/common 31.66.0 → 31.67.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.
@@ -24,7 +24,9 @@
24
24
  * ```
25
25
  */
26
26
  export function getArrayPage(originalArray, options) {
27
- const chunks = chunkArray(originalArray, { chunkSize: options.countPerPage });
27
+ const chunks = chunkArray(originalArray, {
28
+ chunkSize: options.countPerPage,
29
+ });
28
30
  return chunks[options.getPage];
29
31
  }
30
32
  /**
@@ -21,5 +21,7 @@
21
21
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
22
22
  */
23
23
  export function repeatArray(repeatCount, array) {
24
- return Array.from({ length: repeatCount }, () => [...array]).flat();
24
+ return Array.from({
25
+ length: repeatCount,
26
+ }, () => [...array]).flat();
25
27
  }
@@ -10,7 +10,10 @@ import { randomString } from '../random/random-string.js';
10
10
  export function shuffleArray(input) {
11
11
  return input
12
12
  .map((value) => {
13
- return { value, sort: randomString() };
13
+ return {
14
+ value,
15
+ sort: randomString(),
16
+ };
14
17
  })
15
18
  .sort((a, b) => a.sort.localeCompare(b.sort))
16
19
  .map(({ value }) => value);
@@ -107,6 +107,9 @@ export class Debounce {
107
107
  }, this.debounceDuration.milliseconds);
108
108
  }
109
109
  this.nextCallTimestamp =
110
- now + convertDuration(this.debounceDuration, { milliseconds: true }).milliseconds;
110
+ now +
111
+ convertDuration(this.debounceDuration, {
112
+ milliseconds: true,
113
+ }).milliseconds;
111
114
  }
112
115
  }
@@ -25,7 +25,9 @@ export function measureExecutionDuration(callback) {
25
25
  try {
26
26
  await result;
27
27
  const endTime = Date.now();
28
- resolve({ milliseconds: endTime - startTime });
28
+ resolve({
29
+ milliseconds: endTime - startTime,
30
+ });
29
31
  }
30
32
  catch (caught) {
31
33
  reject(ensureError(caught));
@@ -20,7 +20,9 @@ export function createBlockingInterval(callback, interval) {
20
20
  finally {
21
21
  isExecuting = false;
22
22
  }
23
- }, convertDuration(interval, { milliseconds: true }).milliseconds);
23
+ }, convertDuration(interval, {
24
+ milliseconds: true,
25
+ }).milliseconds);
24
26
  return {
25
27
  intervalId,
26
28
  clearInterval() {
@@ -1,4 +1,4 @@
1
- import { type JsonCompatibleValue } from '@augment-vir/core';
1
+ import { type JsonCompatibleValue, type PartialWithUndefined } from '@augment-vir/core';
2
2
  import { type IsUnknown, type Jsonify, type Writable } from 'type-fest';
3
3
  /**
4
4
  * Deeply copy an object through JSON. This is the fastest deep copy, but the input must already be
@@ -34,4 +34,6 @@ import { type IsUnknown, type Jsonify, type Writable } from 'type-fest';
34
34
  *
35
35
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
36
36
  */
37
- export declare function copyThroughJson<const T>(input: T): IsUnknown<T> extends true ? JsonCompatibleValue : Writable<Jsonify<T>>;
37
+ export declare function copyThroughJson<const T>(input: T, { enableUnsafeCopyAll, }?: Readonly<PartialWithUndefined<{
38
+ enableUnsafeCopyAll: boolean;
39
+ }>> | undefined): IsUnknown<T> extends true ? JsonCompatibleValue : Writable<Jsonify<T>>;
@@ -33,9 +33,10 @@ import { safeJsonStringify } from './safe-json-stringify.js';
33
33
  *
34
34
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
35
35
  */
36
- export function copyThroughJson(input) {
36
+ export function copyThroughJson(input, { enableUnsafeCopyAll, } = {}) {
37
37
  try {
38
- return JSON.parse(safeJsonStringify(input));
38
+ const stringified = enableUnsafeCopyAll ? JSON.stringify(input) : safeJsonStringify(input);
39
+ return JSON.parse(stringified);
39
40
  /* node:coverage ignore next 4 */
40
41
  }
41
42
  catch (error) {
@@ -117,7 +117,10 @@ export const defaultLogColorConfig = {
117
117
  colors: [logColors.normalWeight],
118
118
  logType: LogOutputType.Standard,
119
119
  },
120
- [LogColorKey.Plain]: { colors: [], logType: LogOutputType.Standard },
120
+ [LogColorKey.Plain]: {
121
+ colors: [],
122
+ logType: LogOutputType.Standard,
123
+ },
121
124
  [LogColorKey.Reset]: {
122
125
  colors: [logColors.reset],
123
126
  logType: LogOutputType.Standard,
@@ -9,7 +9,9 @@ import { log } from './log.js';
9
9
  */
10
10
  export async function logCountdown(start, logCallback = log.warning) {
11
11
  logCallback(String(start));
12
- await wait({ seconds: 1.5 });
12
+ await wait({
13
+ seconds: 1.5,
14
+ });
13
15
  if (start) {
14
16
  return await logCountdown(start - 1, logCallback);
15
17
  }
@@ -28,7 +28,10 @@ async function createToLogString() {
28
28
  ? ''
29
29
  : options.colorConfig[LogColorKey.Reset].colors.join(''),
30
30
  ].join('');
31
- return { text, css: undefined };
31
+ return {
32
+ text,
33
+ css: undefined,
34
+ };
32
35
  };
33
36
  },
34
37
  /**
@@ -60,7 +63,10 @@ async function createToLogString() {
60
63
  ? ''
61
64
  : options.colorConfig[LogColorKey.Reset].colors.join(''),
62
65
  ].join('');
63
- return { text, css };
66
+ return {
67
+ text,
68
+ css,
69
+ };
64
70
  };
65
71
  },
66
72
  /* node:coverage enable */
@@ -24,11 +24,17 @@ isRuntimeEnv(RuntimeEnv.Node)
24
24
  : /* node:coverage enable */
25
25
  {
26
26
  [LogOutputType.Error]({ text, css }) {
27
- console.error(addPrefix({ value: text, prefix: '%c' }), css);
27
+ console.error(addPrefix({
28
+ value: text,
29
+ prefix: '%c',
30
+ }), css);
28
31
  },
29
32
  [LogOutputType.Standard]({ text, css }) {
30
33
  // eslint-disable-next-line no-console
31
- console.log(addPrefix({ value: text, prefix: '%c' }), css);
34
+ console.log(addPrefix({
35
+ value: text,
36
+ prefix: '%c',
37
+ }), css);
32
38
  },
33
39
  };
34
40
  /**
@@ -81,5 +87,8 @@ export function createArrayLogger(options) {
81
87
  logs.stdout.push(text);
82
88
  },
83
89
  }, options);
84
- return { log, logs };
90
+ return {
91
+ log,
92
+ logs,
93
+ };
85
94
  }
@@ -161,7 +161,10 @@ export function truncateNumber(originalValue, { customSuffixes = defaultTruncati
161
161
  }
162
162
  // handle too big or too small edge cases
163
163
  if (requiresScientificNotation(inputNumber)) {
164
- return truncateScientificNotation({ input: inputNumber, maxLength });
164
+ return truncateScientificNotation({
165
+ input: inputNumber,
166
+ maxLength,
167
+ });
165
168
  }
166
169
  const numberAsString = String(inputNumber);
167
170
  const smallResult = handleSmallNumbers(numberAsString, maxLength);
@@ -28,7 +28,9 @@ export function mergeDeep(...inputs) {
28
28
  }
29
29
  else if (!check.isObject(result)) {
30
30
  /** If result isn't an object then we need to make it into one. */
31
- result = { ...individualInput };
31
+ result = {
32
+ ...individualInput,
33
+ };
32
34
  }
33
35
  Object.entries(individualInput).forEach(([key, value,]) => {
34
36
  if (!mergeProps[key]) {
@@ -17,7 +17,9 @@ import { getObjectTypedEntries } from './object-entries.js';
17
17
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
18
18
  */
19
19
  export function mergeDefinedProperties(original, ...overrides) {
20
- const finalObject = { ...original };
20
+ const finalObject = {
21
+ ...original,
22
+ };
21
23
  overrides.forEach((entry) => {
22
24
  if (!entry) {
23
25
  return;
@@ -23,7 +23,10 @@ import { removeSuffix } from '../string/suffix.js';
23
23
  */
24
24
  export function getEsmPath(importMeta) {
25
25
  const filePath = new URL('', importMeta.url).pathname;
26
- const dirPath = removeSuffix({ value: new URL('.', importMeta.url).pathname, suffix: '/' });
26
+ const dirPath = removeSuffix({
27
+ value: new URL('.', importMeta.url).pathname,
28
+ suffix: '/',
29
+ });
27
30
  return {
28
31
  filePath,
29
32
  dirPath,
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable unicorn/prefer-code-point */
2
- /* eslint-disable sonarjs/no-control-regex */
3
2
  /* eslint-disable no-control-regex */
4
3
  import { getByteLength } from '../string/length.js';
5
4
  import { safeSplit } from '../string/split.js';
@@ -90,7 +89,6 @@ function truncate(string, byteLength) {
90
89
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
91
90
  segment = string[i];
92
91
  if (isHighSurrogate(codePoint) && isLowSurrogate(string.charCodeAt(i + 1))) {
93
- // eslint-disable-next-line sonarjs/updated-loop-counter
94
92
  i += 1;
95
93
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
96
94
  segment += string[i];
@@ -23,7 +23,10 @@ export function replaceExtension({ newExtension, path, }) {
23
23
  return [
24
24
  dirname,
25
25
  basename,
26
- addPrefix({ value: newExtension, prefix: '.' }),
26
+ addPrefix({
27
+ value: newExtension,
28
+ prefix: '.',
29
+ }),
27
30
  tail,
28
31
  ].join('');
29
32
  }
@@ -54,10 +57,12 @@ export function hasExtension(path) {
54
57
  * @category Package : @augment-vir/common
55
58
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
56
59
  */
57
- /* node:coverage ignore next 3: cannot test both on a single system. */
60
+ /* node:coverage ignore next 5: cannot test both on a single system. */
58
61
  export const defaultSep = isRuntimeEnv(RuntimeEnv.Web)
59
62
  ? '/'
60
- : await wrapInTry(async () => (await import('node:path')).sep, { fallbackValue: '/' });
63
+ : await wrapInTry(async () => (await import('node:path')).sep, {
64
+ fallbackValue: '/',
65
+ });
61
66
  /**
62
67
  * Extracts a path's extension, amongst other things, from the given path, without relying on
63
68
  * Node.js built-in packages (this works in a browser).
@@ -99,10 +99,14 @@ export class PromiseQueue extends ListenTarget {
99
99
  this.currentlyAwaiting = item;
100
100
  item.original()
101
101
  .then((result) => {
102
- this.handleItemSettle({ resolution: result });
102
+ this.handleItemSettle({
103
+ resolution: result,
104
+ });
103
105
  })
104
106
  .catch((error) => {
105
- this.handleItemSettle({ rejection: error });
107
+ this.handleItemSettle({
108
+ rejection: error,
109
+ });
106
110
  });
107
111
  return true;
108
112
  }
@@ -14,7 +14,9 @@ export class PromiseTimeoutError extends Error {
14
14
  constructor(duration, failureMessage) {
15
15
  super([
16
16
  failureMessage,
17
- `Promised timed out after ${convertDuration(duration, { milliseconds: true }).milliseconds} ms.`,
17
+ `Promised timed out after ${convertDuration(duration, {
18
+ milliseconds: true,
19
+ }).milliseconds} ms.`,
18
20
  ]
19
21
  .filter(check.isTruthy)
20
22
  .join(': '));
@@ -33,7 +35,9 @@ export function wrapPromiseInTimeout(duration, originalPromise, failureMessage)
33
35
  const isInfinity = Object.values(duration).some((value) => value && check.isInfinite(value));
34
36
  const milliseconds = isInfinity
35
37
  ? Infinity
36
- : convertDuration(duration, { milliseconds: true }).milliseconds;
38
+ : convertDuration(duration, {
39
+ milliseconds: true,
40
+ }).milliseconds;
37
41
  return new Promise(async (resolve, reject) => {
38
42
  const timeoutId = milliseconds === Infinity
39
43
  ? undefined
@@ -24,7 +24,10 @@ import { randomInteger } from './random-integer.js';
24
24
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
25
25
  */
26
26
  export function randomBoolean(percentLikelyToBeTrue = 50) {
27
- return (randomInteger({ min: 0, max: 99 }) <
27
+ return (randomInteger({
28
+ min: 0,
29
+ max: 99,
30
+ }) <
28
31
  clamp(Math.floor(percentLikelyToBeTrue), {
29
32
  min: 0,
30
33
  max: 100,
@@ -10,7 +10,10 @@ import { ensureMinMax } from '@augment-vir/core';
10
10
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
11
  */
12
12
  export function randomInteger({ min: rawMin, max: rawMax }) {
13
- const { min, max } = ensureMinMax({ min: Math.floor(rawMin), max: Math.floor(rawMax) });
13
+ const { min, max } = ensureMinMax({
14
+ min: Math.floor(rawMin),
15
+ max: Math.floor(rawMax),
16
+ });
14
17
  const range = max - min + 1;
15
18
  const bitsNeeded = Math.ceil(Math.log2(range));
16
19
  const neededBytes = Math.ceil(bitsNeeded / 8);
@@ -40,8 +40,12 @@ export function camelCaseToKebabCase(rawCamelCase) {
40
40
  .reduce((accum, currentLetter, index, originalString) => {
41
41
  const previousLetter = index > 0 ? originalString[index - 1] || '' : '';
42
42
  const nextLetter = index < originalString.length - 1 ? originalString[index + 1] || '' : '';
43
- const possibleWordBoundary = isCase(previousLetter, StringCase.Lower, { rejectNoCaseCharacters: true }) ||
44
- isCase(nextLetter, StringCase.Lower, { rejectNoCaseCharacters: true });
43
+ const possibleWordBoundary = isCase(previousLetter, StringCase.Lower, {
44
+ rejectNoCaseCharacters: true,
45
+ }) ||
46
+ isCase(nextLetter, StringCase.Lower, {
47
+ rejectNoCaseCharacters: true,
48
+ });
45
49
  if (currentLetter === currentLetter.toLowerCase() ||
46
50
  index === 0 ||
47
51
  !possibleWordBoundary) {
@@ -24,7 +24,9 @@ export function splitIncludeSplit(original, splitDelimiter, { caseSensitive }) {
24
24
  caseSensitive,
25
25
  includeLength: true,
26
26
  });
27
- const splitter = setRegExpCaseSensitivity(splitDelimiter, { caseSensitive });
27
+ const splitter = setRegExpCaseSensitivity(splitDelimiter, {
28
+ caseSensitive,
29
+ });
28
30
  const splits = original.split(splitter);
29
31
  return splits.reduce((accum, current, index) => {
30
32
  // this will be undefined on the last index
@@ -9,7 +9,9 @@ import { addRegExpFlags, setRegExpCaseSensitivity } from '@augment-vir/core';
9
9
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
10
10
  */
11
11
  export function findSubstringIndexes({ searchIn, searchFor, caseSensitive, includeLength, }) {
12
- const searchRegExp = addRegExpFlags(setRegExpCaseSensitivity(searchFor, { caseSensitive }), 'g');
12
+ const searchRegExp = addRegExpFlags(setRegExpCaseSensitivity(searchFor, {
13
+ caseSensitive,
14
+ }), 'g');
13
15
  const indexes = [];
14
16
  const indexesAndLengths = [];
15
17
  searchIn.replace(searchRegExp, (...matchResults) => {
@@ -29,7 +31,10 @@ export function findSubstringIndexes({ searchIn, searchFor, caseSensitive, inclu
29
31
  if (typeof regExpMatch !== 'string') {
30
32
  throw new TypeError(`regExpMatch should've been a string but was ${typeof regExpMatch}!`);
31
33
  }
32
- indexesAndLengths.push({ index: matchIndex, length: regExpMatch.length });
34
+ indexesAndLengths.push({
35
+ index: matchIndex,
36
+ length: regExpMatch.length,
37
+ });
33
38
  indexes.push(matchIndex);
34
39
  const originalMatch = matchResults[0];
35
40
  // this is used as a type safety catch and cannot actually be triggered on purpose
@@ -23,7 +23,10 @@ export const pxSuffix = 'px';
23
23
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
24
24
  */
25
25
  export function addPx(input) {
26
- return addSuffix({ value: input, suffix: pxSuffix });
26
+ return addSuffix({
27
+ value: input,
28
+ suffix: pxSuffix,
29
+ });
27
30
  }
28
31
  /**
29
32
  * Removes the `'px'` suffix from a string if it exists.
@@ -34,7 +37,10 @@ export function addPx(input) {
34
37
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
35
38
  */
36
39
  export function removePx(input) {
37
- return toEnsuredNumber(removeSuffix({ value: input, suffix: pxSuffix }));
40
+ return toEnsuredNumber(removeSuffix({
41
+ value: input,
42
+ suffix: pxSuffix,
43
+ }));
38
44
  }
39
45
  /**
40
46
  * Adds the `'%'` suffix to a string if it does not already exist.
@@ -44,7 +50,10 @@ export function removePx(input) {
44
50
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
45
51
  */
46
52
  export function addPercent(input) {
47
- return addSuffix({ value: input, suffix: percentSuffix });
53
+ return addSuffix({
54
+ value: input,
55
+ suffix: percentSuffix,
56
+ });
48
57
  }
49
58
  /**
50
59
  * Removes the `'%'` suffix from a string if it exists.
@@ -55,7 +64,10 @@ export function addPercent(input) {
55
64
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
56
65
  */
57
66
  export function removePercent(input) {
58
- return toEnsuredNumber(removeSuffix({ value: input, suffix: percentSuffix }));
67
+ return toEnsuredNumber(removeSuffix({
68
+ value: input,
69
+ suffix: percentSuffix,
70
+ }));
59
71
  }
60
72
  /**
61
73
  * Adds a suffix to a string if it does not already exist.
@@ -16,5 +16,11 @@ import { addSuffix } from './suffix.js';
16
16
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
17
  */
18
18
  export function wrapString({ value, wrapper }) {
19
- return addPrefix({ value: addSuffix({ value, suffix: wrapper }), prefix: wrapper });
19
+ return addPrefix({
20
+ value: addSuffix({
21
+ value,
22
+ suffix: wrapper,
23
+ }),
24
+ prefix: wrapper,
25
+ });
20
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "31.66.0",
3
+ "version": "31.67.1",
4
4
  "description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
5
5
  "keywords": [
6
6
  "augment",
@@ -40,9 +40,9 @@
40
40
  "test:web": "virmator --no-deps test web"
41
41
  },
42
42
  "dependencies": {
43
- "@augment-vir/assert": "^31.66.0",
44
- "@augment-vir/core": "^31.66.0",
45
- "@date-vir/duration": "^8.1.1",
43
+ "@augment-vir/assert": "^31.67.1",
44
+ "@augment-vir/core": "^31.67.1",
45
+ "@date-vir/duration": "^8.2.0",
46
46
  "ansi-styles": "^6.2.3",
47
47
  "deepcopy-esm": "^2.1.1",
48
48
  "json5": "^2.2.3",