utilium 0.7.5 → 0.7.7
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/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
export type Sep = '_' | '-';
|
2
2
|
export type Part = `${number}.${number}.${number}`;
|
3
|
-
export type
|
3
|
+
export type WithPre = `${Part}${Sep}${string}${Sep | '.'}${Part | number}`;
|
4
|
+
export type Full = Part | WithPre;
|
4
5
|
type Type<S extends string, Acc extends string = ''> = S extends `${infer First}${infer Rest}` ? (First extends Sep | '.' ? Acc : Type<Rest, `${Acc}${First}`>) : Acc;
|
5
6
|
export type Parse<T extends Full, StripCore extends boolean> = T extends `${infer Core}${Sep}${infer Rest}` ? Rest extends `${infer U}` ? {
|
6
7
|
full: T;
|
@@ -13,6 +14,7 @@ export type Parse<T extends Full, StripCore extends boolean> = T extends `${infe
|
|
13
14
|
core: T;
|
14
15
|
display: T;
|
15
16
|
} : never;
|
17
|
+
export declare const regex: RegExp;
|
16
18
|
/**
|
17
19
|
* Parses a semver version, including compile-time results
|
18
20
|
* @param full the full version to parse
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { capitalize } from './string.js';
|
2
|
+
export const regex = /^(?<core>\d+\.\d+\.\d+)(?:[-_](?<type>[^-_.]+)[-_.](?<pre>\d*(?:\.\d+)*))?/;
|
2
3
|
export function parse(full, stripCore) {
|
3
|
-
const { type, pre, core } =
|
4
|
+
const { type, pre, core } = regex.exec(full).groups;
|
4
5
|
const display = type ? `${stripCore && core == '1.0.0' ? '' : core + ' '}${capitalize(type)}${pre ? ` ${pre}` : ''}` : core;
|
5
6
|
return { full, core, pre, type, display };
|
6
7
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -4,7 +4,9 @@ export type Sep = '_' | '-';
|
|
4
4
|
|
5
5
|
export type Part = `${number}.${number}.${number}`;
|
6
6
|
|
7
|
-
export type
|
7
|
+
export type WithPre = `${Part}${Sep}${string}${Sep | '.'}${Part | number}`;
|
8
|
+
|
9
|
+
export type Full = Part | WithPre;
|
8
10
|
|
9
11
|
type Type<S extends string, Acc extends string = ''> = S extends `${infer First}${infer Rest}` ? (First extends Sep | '.' ? Acc : Type<Rest, `${Acc}${First}`>) : Acc;
|
10
12
|
|
@@ -30,6 +32,8 @@ export type Parse<T extends Full, StripCore extends boolean> = T extends `${infe
|
|
30
32
|
}
|
31
33
|
: never;
|
32
34
|
|
35
|
+
export const regex = /^(?<core>\d+\.\d+\.\d+)(?:[-_](?<type>[^-_.]+)[-_.](?<pre>\d*(?:\.\d+)*))?/;
|
36
|
+
|
33
37
|
/**
|
34
38
|
* Parses a semver version, including compile-time results
|
35
39
|
* @param full the full version to parse
|
@@ -38,7 +42,7 @@ export type Parse<T extends Full, StripCore extends boolean> = T extends `${infe
|
|
38
42
|
export function parse<const T extends Full>(full: T): Parse<T, false>;
|
39
43
|
export function parse<const T extends Full, const S extends boolean>(full: T, stripCore: S): Parse<T, S>;
|
40
44
|
export function parse<const T extends Full, const S extends boolean>(full: T, stripCore?: S): Parse<T, S> {
|
41
|
-
const { type, pre, core } =
|
45
|
+
const { type, pre, core } = regex.exec(full)!.groups!;
|
42
46
|
const display = type ? `${stripCore && core == '1.0.0' ? '' : core + ' '}${capitalize(type)}${pre ? ` ${pre}` : ''}` : core;
|
43
47
|
return { full, core, pre, type, display } as Parse<T, S>;
|
44
48
|
}
|