@augment-vir/common
Advanced tools
Comparing version 28.0.2 to 28.1.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.clamp = exports.round = exports.wrapNumber = exports.toEnsuredNumber = exports.ensureMinAndMax = exports.doesRequireScientificNotation = exports.convertIntoNumber = exports.addCommasToNumber = exports.NaNString = void 0; | ||
exports.clamp = exports.round = exports.wrapNumber = exports.toMaybeNumber = exports.toEnsuredNumber = exports.convertIntoNumber = exports.toNumber = exports.ensureMinAndMax = exports.doesRequireScientificNotation = exports.addCommasToNumber = exports.NaNString = void 0; | ||
const common_string_1 = require("./common-string"); | ||
@@ -28,14 +28,2 @@ const regexp_1 = require("./regexp"); | ||
exports.addCommasToNumber = addCommasToNumber; | ||
function convertIntoNumber(input) { | ||
if (typeof input === 'number') { | ||
return input; | ||
} | ||
else if (typeof input === 'string') { | ||
return Number((0, common_string_1.removeCommasFromNumberString)(input)); | ||
} | ||
else { | ||
return Number(input); | ||
} | ||
} | ||
exports.convertIntoNumber = convertIntoNumber; | ||
function doesRequireScientificNotation(input) { | ||
@@ -58,6 +46,36 @@ return String(input).includes('e'); | ||
exports.ensureMinAndMax = ensureMinAndMax; | ||
/** | ||
* Tries to convert the input into a number. Handles strings with commas. Note: this might return | ||
* `NaN`. | ||
*/ | ||
function toNumber(input) { | ||
if (typeof input === 'number') { | ||
return input; | ||
} | ||
else if (typeof input === 'string') { | ||
return Number((0, common_string_1.removeCommasFromNumberString)(input)); | ||
} | ||
else { | ||
return Number(input); | ||
} | ||
} | ||
exports.toNumber = toNumber; | ||
/** @deprecated Use {@link toNumber} instead. */ | ||
exports.convertIntoNumber = toNumber; | ||
/** Tries to convert the input into a number and throws an error if `NaN` is created. */ | ||
function toEnsuredNumber(input) { | ||
const numeric = Number(input); | ||
const numeric = toMaybeNumber(input); | ||
if (numeric == undefined) { | ||
throw new Error(`Cannot convert to a number: ${input}`); | ||
} | ||
else { | ||
return numeric; | ||
} | ||
} | ||
exports.toEnsuredNumber = toEnsuredNumber; | ||
/** Tries to convert the input into a number and returns `undefined` if `NaN` is created. */ | ||
function toMaybeNumber(input) { | ||
const numeric = toNumber(input); | ||
if (isNaN(numeric)) { | ||
throw new Error(`Cannot convert given input to a number: ${input}`); | ||
return undefined; | ||
} | ||
@@ -68,3 +86,3 @@ else { | ||
} | ||
exports.toEnsuredNumber = toEnsuredNumber; | ||
exports.toMaybeNumber = toMaybeNumber; | ||
/** | ||
@@ -71,0 +89,0 @@ * If the given value is outside the given min/max bounds, instead of clamping the number (as the |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.typedSplit = exports.getAllIndexesOf = exports.escapeStringForRegExp = exports.replaceStringAtIndex = exports.camelCaseToKebabCase = exports.isCase = exports.hasCase = exports.StringCaseEnum = exports.kebabCaseToCamelCase = exports.capitalizeFirstLetter = exports.splitIncludeSplit = exports.collapseWhiteSpace = exports.removeCommasFromNumberString = exports.removeColor = exports.removeAnsiEscapeCodes = exports.joinWithFinalConjunction = void 0; | ||
exports.typedSplit = exports.getAllIndexesOf = exports.escapeStringForRegExp = exports.replaceStringAtIndex = exports.camelCaseToKebabCase = exports.isCase = exports.hasCase = exports.StringCaseEnum = exports.kebabCaseToCamelCase = exports.capitalizeFirstLetter = exports.splitIncludeSplit = exports.collapseWhiteSpace = exports.removeCommasFromNumberString = exports.removeColor = exports.removeAnsiEscapeCodes = exports.wrapString = exports.joinWithFinalConjunction = void 0; | ||
const ansi_1 = require("./ansi"); | ||
@@ -31,2 +31,10 @@ const regexp_1 = require("./regexp"); | ||
exports.joinWithFinalConjunction = joinWithFinalConjunction; | ||
/** Wraps `value` on both sides with `wrapper`. */ | ||
function wrapString({ value, wrapper }) { | ||
return [ | ||
wrapper, | ||
wrapper, | ||
].join(value); | ||
} | ||
exports.wrapString = wrapString; | ||
function removeAnsiEscapeCodes(input) { | ||
@@ -33,0 +41,0 @@ return input.replace(ansi_1.ansiRegex, ''); |
@@ -24,13 +24,2 @@ import { removeCommasFromNumberString } from './common-string'; | ||
} | ||
export function convertIntoNumber(input) { | ||
if (typeof input === 'number') { | ||
return input; | ||
} | ||
else if (typeof input === 'string') { | ||
return Number(removeCommasFromNumberString(input)); | ||
} | ||
else { | ||
return Number(input); | ||
} | ||
} | ||
export function doesRequireScientificNotation(input) { | ||
@@ -51,6 +40,34 @@ return String(input).includes('e'); | ||
} | ||
/** | ||
* Tries to convert the input into a number. Handles strings with commas. Note: this might return | ||
* `NaN`. | ||
*/ | ||
export function toNumber(input) { | ||
if (typeof input === 'number') { | ||
return input; | ||
} | ||
else if (typeof input === 'string') { | ||
return Number(removeCommasFromNumberString(input)); | ||
} | ||
else { | ||
return Number(input); | ||
} | ||
} | ||
/** @deprecated Use {@link toNumber} instead. */ | ||
export const convertIntoNumber = toNumber; | ||
/** Tries to convert the input into a number and throws an error if `NaN` is created. */ | ||
export function toEnsuredNumber(input) { | ||
const numeric = Number(input); | ||
const numeric = toMaybeNumber(input); | ||
if (numeric == undefined) { | ||
throw new Error(`Cannot convert to a number: ${input}`); | ||
} | ||
else { | ||
return numeric; | ||
} | ||
} | ||
/** Tries to convert the input into a number and returns `undefined` if `NaN` is created. */ | ||
export function toMaybeNumber(input) { | ||
const numeric = toNumber(input); | ||
if (isNaN(numeric)) { | ||
throw new Error(`Cannot convert given input to a number: ${input}`); | ||
return undefined; | ||
} | ||
@@ -57,0 +74,0 @@ else { |
@@ -27,2 +27,9 @@ import { ansiRegex } from './ansi'; | ||
} | ||
/** Wraps `value` on both sides with `wrapper`. */ | ||
export function wrapString({ value, wrapper }) { | ||
return [ | ||
wrapper, | ||
wrapper, | ||
].join(value); | ||
} | ||
export function removeAnsiEscapeCodes(input) { | ||
@@ -29,0 +36,0 @@ return input.replace(ansiRegex, ''); |
export declare const NaNString: string; | ||
export declare function addCommasToNumber(input: number | string): string; | ||
export declare function convertIntoNumber(input: unknown): number; | ||
export declare function doesRequireScientificNotation(input: number): boolean; | ||
@@ -16,4 +15,14 @@ /** | ||
}; | ||
export declare function toEnsuredNumber(input: any): number; | ||
/** | ||
* Tries to convert the input into a number. Handles strings with commas. Note: this might return | ||
* `NaN`. | ||
*/ | ||
export declare function toNumber(input: unknown): number; | ||
/** @deprecated Use {@link toNumber} instead. */ | ||
export declare const convertIntoNumber: typeof toNumber; | ||
/** Tries to convert the input into a number and throws an error if `NaN` is created. */ | ||
export declare function toEnsuredNumber(input: unknown): number; | ||
/** Tries to convert the input into a number and returns `undefined` if `NaN` is created. */ | ||
export declare function toMaybeNumber(input: unknown): number | undefined; | ||
/** | ||
* If the given value is outside the given min/max bounds, instead of clamping the number (as the | ||
@@ -20,0 +29,0 @@ * `clamp` function does), this function wraps the value around to the next bound. |
@@ -13,2 +13,7 @@ import { PartialAndUndefined } from './object/object'; | ||
export declare function joinWithFinalConjunction(list: ReadonlyArray<any>, conjunction?: string): string; | ||
/** Wraps `value` on both sides with `wrapper`. */ | ||
export declare function wrapString({ value, wrapper }: { | ||
value: string; | ||
wrapper: string; | ||
}): string; | ||
export declare function removeAnsiEscapeCodes(input: string): string; | ||
@@ -15,0 +20,0 @@ export declare const removeColor: typeof removeAnsiEscapeCodes; |
@@ -16,7 +16,7 @@ import { NoInputsFunction } from './function'; | ||
export declare function wrapInTry<Value extends Promise<any>>(callback: NoInputsFunction<Value>, options?: undefined | { | ||
handleError?: undefined; | ||
handleError?: never; | ||
fallbackValue?: never; | ||
}): Promise<Error | Awaited<Value>>; | ||
export declare function wrapInTry<Value>(callback: NoInputsFunction<Value>, options?: undefined | { | ||
handleError?: undefined; | ||
handleError?: never; | ||
fallbackValue?: never; | ||
@@ -23,0 +23,0 @@ }): Error | Value; |
{ | ||
"name": "@augment-vir/common", | ||
"version": "28.0.2", | ||
"version": "28.1.0", | ||
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common", | ||
@@ -5,0 +5,0 @@ "bugs": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167138
4109