@augment-vir/common 16.3.0 → 16.4.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.
- package/dist/cjs/augments/number.js +13 -0
- package/dist/cjs/augments/string/suffixes.js +40 -0
- package/dist/cjs/index.js +2 -1
- package/dist/esm/augments/number.js +9 -0
- package/dist/esm/augments/string/suffixes.js +31 -0
- package/dist/esm/index.js +2 -1
- package/dist/types/augments/number.d.ts +1 -0
- package/dist/types/augments/object/enum.d.ts +6 -5
- package/dist/types/augments/string/suffixes.d.ts +11 -0
- package/dist/types/augments/tuple.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/package.json +3 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toEnsuredNumber = void 0;
|
|
4
|
+
function toEnsuredNumber(input) {
|
|
5
|
+
const numeric = Number(input);
|
|
6
|
+
if (isNaN(numeric)) {
|
|
7
|
+
throw new Error(`Cannot convert given input to a number: ${input}`);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return numeric;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.toEnsuredNumber = toEnsuredNumber;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeSuffix = exports.addSuffix = exports.removePercent = exports.addPercent = exports.removePx = exports.addPx = exports.pxSuffix = exports.percentSuffix = void 0;
|
|
4
|
+
const number_1 = require("../number");
|
|
5
|
+
exports.percentSuffix = '%';
|
|
6
|
+
exports.pxSuffix = 'px';
|
|
7
|
+
function addPx(input) {
|
|
8
|
+
return addSuffix(input, exports.pxSuffix);
|
|
9
|
+
}
|
|
10
|
+
exports.addPx = addPx;
|
|
11
|
+
function removePx(input) {
|
|
12
|
+
return (0, number_1.toEnsuredNumber)(input.replace(/px$/, ''));
|
|
13
|
+
}
|
|
14
|
+
exports.removePx = removePx;
|
|
15
|
+
function addPercent(input) {
|
|
16
|
+
return addSuffix(input, exports.percentSuffix);
|
|
17
|
+
}
|
|
18
|
+
exports.addPercent = addPercent;
|
|
19
|
+
function removePercent(input) {
|
|
20
|
+
return (0, number_1.toEnsuredNumber)(removeSuffix(input, exports.percentSuffix));
|
|
21
|
+
}
|
|
22
|
+
exports.removePercent = removePercent;
|
|
23
|
+
function addSuffix(input, suffix) {
|
|
24
|
+
if (String(input).endsWith(suffix)) {
|
|
25
|
+
return String(input);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return `${String(input)}${suffix}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.addSuffix = addSuffix;
|
|
32
|
+
function removeSuffix(input, suffix) {
|
|
33
|
+
if (input.endsWith(suffix)) {
|
|
34
|
+
return input.substring(0, input.length - suffix.length);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return input;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.removeSuffix = removeSuffix;
|
package/dist/cjs/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(require("./augments/function"), exports);
|
|
|
26
26
|
__exportStar(require("./augments/json"), exports);
|
|
27
27
|
__exportStar(require("./augments/json-compatible"), exports);
|
|
28
28
|
__exportStar(require("./augments/map"), exports);
|
|
29
|
+
__exportStar(require("./augments/number"), exports);
|
|
29
30
|
__exportStar(require("./augments/object/enum"), exports);
|
|
30
31
|
__exportStar(require("./augments/object/filter-object"), exports);
|
|
31
32
|
__exportStar(require("./augments/object/has-key"), exports);
|
|
@@ -37,10 +38,10 @@ __exportStar(require("./augments/object/object"), exports);
|
|
|
37
38
|
__exportStar(require("./augments/object/object-entries"), exports);
|
|
38
39
|
__exportStar(require("./augments/object/pick-deep"), exports);
|
|
39
40
|
__exportStar(require("./augments/object/typed-has-property"), exports);
|
|
40
|
-
__exportStar(require("./augments/pixel"), exports);
|
|
41
41
|
__exportStar(require("./augments/promise"), exports);
|
|
42
42
|
__exportStar(require("./augments/regexp"), exports);
|
|
43
43
|
__exportStar(require("./augments/runtime-type-of"), exports);
|
|
44
|
+
__exportStar(require("./augments/string/suffixes"), exports);
|
|
44
45
|
__exportStar(require("./augments/string/url"), exports);
|
|
45
46
|
__exportStar(require("./augments/string/uuid"), exports);
|
|
46
47
|
__exportStar(require("./augments/time"), exports);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { toEnsuredNumber } from '../number';
|
|
2
|
+
export const percentSuffix = '%';
|
|
3
|
+
export const pxSuffix = 'px';
|
|
4
|
+
export function addPx(input) {
|
|
5
|
+
return addSuffix(input, pxSuffix);
|
|
6
|
+
}
|
|
7
|
+
export function removePx(input) {
|
|
8
|
+
return toEnsuredNumber(input.replace(/px$/, ''));
|
|
9
|
+
}
|
|
10
|
+
export function addPercent(input) {
|
|
11
|
+
return addSuffix(input, percentSuffix);
|
|
12
|
+
}
|
|
13
|
+
export function removePercent(input) {
|
|
14
|
+
return toEnsuredNumber(removeSuffix(input, percentSuffix));
|
|
15
|
+
}
|
|
16
|
+
export function addSuffix(input, suffix) {
|
|
17
|
+
if (String(input).endsWith(suffix)) {
|
|
18
|
+
return String(input);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return `${String(input)}${suffix}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function removeSuffix(input, suffix) {
|
|
25
|
+
if (input.endsWith(suffix)) {
|
|
26
|
+
return input.substring(0, input.length - suffix.length);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return input;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from './augments/function';
|
|
|
10
10
|
export * from './augments/json';
|
|
11
11
|
export * from './augments/json-compatible';
|
|
12
12
|
export * from './augments/map';
|
|
13
|
+
export * from './augments/number';
|
|
13
14
|
export * from './augments/object/enum';
|
|
14
15
|
export * from './augments/object/filter-object';
|
|
15
16
|
export * from './augments/object/has-key';
|
|
@@ -21,10 +22,10 @@ export * from './augments/object/object';
|
|
|
21
22
|
export * from './augments/object/object-entries';
|
|
22
23
|
export * from './augments/object/pick-deep';
|
|
23
24
|
export * from './augments/object/typed-has-property';
|
|
24
|
-
export * from './augments/pixel';
|
|
25
25
|
export * from './augments/promise';
|
|
26
26
|
export * from './augments/regexp';
|
|
27
27
|
export * from './augments/runtime-type-of';
|
|
28
|
+
export * from './augments/string/suffixes';
|
|
28
29
|
export * from './augments/string/url';
|
|
29
30
|
export * from './augments/string/uuid';
|
|
30
31
|
export * from './augments/time';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toEnsuredNumber(input: any): number;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export declare function
|
|
1
|
+
export type EnumBaseType = Record<string, number | string>;
|
|
2
|
+
export declare function getEnumTypedKeys<T extends EnumBaseType>(input: T): (keyof T)[];
|
|
3
|
+
export declare function getEnumTypedValues<T extends EnumBaseType>(input: T): T[keyof T][];
|
|
3
4
|
/** Check if the given value is within the given enum. */
|
|
4
|
-
export declare function isEnumValue<T extends
|
|
5
|
+
export declare function isEnumValue<T extends EnumBaseType>(input: unknown, checkEnum: T): input is T[keyof T];
|
|
5
6
|
/** Interpret a primitive as an enum value with type safety. */
|
|
6
|
-
export declare function ensureEnum<const ValueType extends `${EnumType[keyof EnumType]}`, const EnumType extends
|
|
7
|
-
export declare function filterToEnumValues<T extends
|
|
7
|
+
export declare function ensureEnum<const ValueType extends `${EnumType[keyof EnumType]}`, const EnumType extends EnumBaseType>(value: ValueType, checkEnum: EnumType): EnumType[keyof EnumType];
|
|
8
|
+
export declare function filterToEnumValues<T extends EnumBaseType>(inputs: ReadonlyArray<unknown>, checkEnum: T, caseInsensitive?: boolean): T[keyof T][];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type WithSuffix<Suffix extends string> = `${string}${Suffix}`;
|
|
2
|
+
export declare const percentSuffix: "%";
|
|
3
|
+
export declare const pxSuffix: "px";
|
|
4
|
+
export type WithPx = WithSuffix<typeof pxSuffix>;
|
|
5
|
+
export type WithPercent = WithSuffix<typeof percentSuffix>;
|
|
6
|
+
export declare function addPx(input: number | string): WithPx;
|
|
7
|
+
export declare function removePx(input: string): number;
|
|
8
|
+
export declare function addPercent(input: number | string): WithPercent;
|
|
9
|
+
export declare function removePercent(input: string): number;
|
|
10
|
+
export declare function addSuffix<const Suffix extends string>(input: unknown, suffix: Suffix): WithSuffix<Suffix>;
|
|
11
|
+
export declare function removeSuffix<const Suffix extends string>(input: WithSuffix<Suffix> | string, suffix: Suffix): string;
|
|
@@ -2,7 +2,7 @@ export type Tuple<ArrayElementGeneric, LengthGeneric extends number> = LengthGen
|
|
|
2
2
|
type _TupleOf<ArrayElementGeneric, LengthGeneric extends number, FullArrayGeneric extends unknown[]> = FullArrayGeneric['length'] extends LengthGeneric ? FullArrayGeneric : _TupleOf<ArrayElementGeneric, LengthGeneric, [ArrayElementGeneric, ...FullArrayGeneric]>;
|
|
3
3
|
export type AtLeastTuple<ArrayElementGeneric, LengthGeneric extends number> = readonly [
|
|
4
4
|
...Tuple<ArrayElementGeneric, LengthGeneric>,
|
|
5
|
-
...
|
|
5
|
+
...ArrayElementGeneric[]
|
|
6
6
|
];
|
|
7
7
|
export declare function isLengthAtLeast<ArrayElementGeneric, LengthGeneric extends number>(array: ReadonlyArray<ArrayElementGeneric | undefined>, length: LengthGeneric): array is AtLeastTuple<ArrayElementGeneric, LengthGeneric>;
|
|
8
8
|
export declare function assertLengthAtLeast<ArrayElementGeneric, LengthGeneric extends number>(array: ReadonlyArray<ArrayElementGeneric | undefined>, length: LengthGeneric, arrayName?: string): asserts array is AtLeastTuple<ArrayElementGeneric, LengthGeneric>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './augments/function';
|
|
|
10
10
|
export * from './augments/json';
|
|
11
11
|
export * from './augments/json-compatible';
|
|
12
12
|
export * from './augments/map';
|
|
13
|
+
export * from './augments/number';
|
|
13
14
|
export * from './augments/object/enum';
|
|
14
15
|
export * from './augments/object/filter-object';
|
|
15
16
|
export * from './augments/object/has-key';
|
|
@@ -21,10 +22,10 @@ export * from './augments/object/object';
|
|
|
21
22
|
export * from './augments/object/object-entries';
|
|
22
23
|
export * from './augments/object/pick-deep';
|
|
23
24
|
export * from './augments/object/typed-has-property';
|
|
24
|
-
export * from './augments/pixel';
|
|
25
25
|
export * from './augments/promise';
|
|
26
26
|
export * from './augments/regexp';
|
|
27
27
|
export * from './augments/runtime-type-of';
|
|
28
|
+
export * from './augments/string/suffixes';
|
|
28
29
|
export * from './augments/string/url';
|
|
29
30
|
export * from './augments/string/uuid';
|
|
30
31
|
export * from './augments/time';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.4.1",
|
|
4
4
|
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/electrovir/augment-vir/issues"
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"test:types": "tsc --noEmit"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"type-fest": "^4.
|
|
27
|
+
"type-fest": "^4.3.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"typescript": "^5.
|
|
30
|
+
"typescript": "^5.2.2"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|