utilium 0.7.5 → 0.7.6
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
@@ -13,6 +13,7 @@ export type Parse<T extends Full, StripCore extends boolean> = T extends `${infe
|
|
13
13
|
core: T;
|
14
14
|
display: T;
|
15
15
|
} : never;
|
16
|
+
export declare const regex: RegExp;
|
16
17
|
/**
|
17
18
|
* Parses a semver version, including compile-time results
|
18
19
|
* @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
@@ -30,6 +30,8 @@ export type Parse<T extends Full, StripCore extends boolean> = T extends `${infe
|
|
30
30
|
}
|
31
31
|
: never;
|
32
32
|
|
33
|
+
export const regex = /^(?<core>\d+\.\d+\.\d+)(?:[-_](?<type>[^-_.]+)[-_.](?<pre>\d*(?:\.\d+)*))?/;
|
34
|
+
|
33
35
|
/**
|
34
36
|
* Parses a semver version, including compile-time results
|
35
37
|
* @param full the full version to parse
|
@@ -38,7 +40,7 @@ export type Parse<T extends Full, StripCore extends boolean> = T extends `${infe
|
|
38
40
|
export function parse<const T extends Full>(full: T): Parse<T, false>;
|
39
41
|
export function parse<const T extends Full, const S extends boolean>(full: T, stripCore: S): Parse<T, S>;
|
40
42
|
export function parse<const T extends Full, const S extends boolean>(full: T, stripCore?: S): Parse<T, S> {
|
41
|
-
const { type, pre, core } =
|
43
|
+
const { type, pre, core } = regex.exec(full)!.groups!;
|
42
44
|
const display = type ? `${stripCore && core == '1.0.0' ? '' : core + ' '}${capitalize(type)}${pre ? ` ${pre}` : ''}` : core;
|
43
45
|
return { full, core, pre, type, display } as Parse<T, S>;
|
44
46
|
}
|