utilium 0.7.4 → 0.7.5

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.
@@ -0,0 +1,23 @@
1
+ export type Sep = '_' | '-';
2
+ export type Part = `${number}.${number}.${number}`;
3
+ export type Full = Part | `${Part}${Sep}${string}${Sep | '.'}${Part | number}`;
4
+ type Type<S extends string, Acc extends string = ''> = S extends `${infer First}${infer Rest}` ? (First extends Sep | '.' ? Acc : Type<Rest, `${Acc}${First}`>) : Acc;
5
+ export type Parse<T extends Full, StripCore extends boolean> = T extends `${infer Core}${Sep}${infer Rest}` ? Rest extends `${infer U}` ? {
6
+ full: T;
7
+ core: Core;
8
+ type: Type<U>;
9
+ pre: U extends `${Type<U>}${Sep | '.'}${infer Pre}` ? Pre : '';
10
+ display: `${StripCore extends true ? Core extends '1.0.0' ? '' : `${Core} ` : `${Core} `}${Capitalize<Type<U>>}${U extends `${Type<U>}${Sep | '.'}${infer Pre}` ? ` ${Pre}` : ''}`;
11
+ } : never : T extends Part ? {
12
+ full: T;
13
+ core: T;
14
+ display: T;
15
+ } : never;
16
+ /**
17
+ * Parses a semver version, including compile-time results
18
+ * @param full the full version to parse
19
+ * @param stripCore Whether to strip the leading core version in the display version when the core version is 1.0.0 (default false)
20
+ */
21
+ export declare function parse<const T extends Full>(full: T): Parse<T, false>;
22
+ export declare function parse<const T extends Full, const S extends boolean>(full: T, stripCore: S): Parse<T, S>;
23
+ export {};
@@ -0,0 +1,6 @@
1
+ import { capitalize } from './string.js';
2
+ export function parse(full, stripCore) {
3
+ const { type, pre, core } = /^(?<core>\d+\.\d+\.\d+)(?:[-_](?<type>[^-_.]+)[-_.](?<pre>\d*(?:\.\d+)*))?/.exec(full).groups;
4
+ const display = type ? `${stripCore && core == '1.0.0' ? '' : core + ' '}${capitalize(type)}${pre ? ` ${pre}` : ''}` : core;
5
+ return { full, core, pre, type, display };
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "description": "Typescript utilies",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/readme.md CHANGED
@@ -1,3 +1,12 @@
1
1
  # Utilium
2
2
 
3
- A bunch of utilies for Typescript that I have found to be very useful
3
+ A bunch of utilies for Typescript. This includes:
4
+
5
+ - Structs (using decorators)
6
+ - Compile-time math types
7
+ - Debugging types
8
+ - Convenience types and functions for strings and objects
9
+ - RNG functions
10
+ - `List`, a class that combines the best aspects of `Set` and arrays
11
+ - `JSONFileMap` and `FolderMap`
12
+ - Version utilities
@@ -0,0 +1,44 @@
1
+ import { capitalize } from './string.js';
2
+
3
+ export type Sep = '_' | '-';
4
+
5
+ export type Part = `${number}.${number}.${number}`;
6
+
7
+ export type Full = Part | `${Part}${Sep}${string}${Sep | '.'}${Part | number}`;
8
+
9
+ type Type<S extends string, Acc extends string = ''> = S extends `${infer First}${infer Rest}` ? (First extends Sep | '.' ? Acc : Type<Rest, `${Acc}${First}`>) : Acc;
10
+
11
+ export type Parse<T extends Full, StripCore extends boolean> = T extends `${infer Core}${Sep}${infer Rest}`
12
+ ? Rest extends `${infer U}`
13
+ ? {
14
+ full: T;
15
+ core: Core;
16
+ type: Type<U>;
17
+ pre: U extends `${Type<U>}${Sep | '.'}${infer Pre}` ? Pre : '';
18
+ display: `${StripCore extends true
19
+ ? Core extends '1.0.0'
20
+ ? ''
21
+ : `${Core} `
22
+ : `${Core} `}${Capitalize<Type<U>>}${U extends `${Type<U>}${Sep | '.'}${infer Pre}` ? ` ${Pre}` : ''}`;
23
+ }
24
+ : never
25
+ : T extends Part
26
+ ? {
27
+ full: T;
28
+ core: T;
29
+ display: T;
30
+ }
31
+ : never;
32
+
33
+ /**
34
+ * Parses a semver version, including compile-time results
35
+ * @param full the full version to parse
36
+ * @param stripCore Whether to strip the leading core version in the display version when the core version is 1.0.0 (default false)
37
+ */
38
+ export function parse<const T extends Full>(full: T): Parse<T, false>;
39
+ export function parse<const T extends Full, const S extends boolean>(full: T, stripCore: S): Parse<T, S>;
40
+ export function parse<const T extends Full, const S extends boolean>(full: T, stripCore?: S): Parse<T, S> {
41
+ const { type, pre, core } = /^(?<core>\d+\.\d+\.\d+)(?:[-_](?<type>[^-_.]+)[-_.](?<pre>\d*(?:\.\d+)*))?/.exec(full)!.groups!;
42
+ const display = type ? `${stripCore && core == '1.0.0' ? '' : core + ' '}${capitalize(type)}${pre ? ` ${pre}` : ''}` : core;
43
+ return { full, core, pre, type, display } as Parse<T, S>;
44
+ }
package/tsconfig.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "lib": ["ESNext"],
4
4
  "module": "NodeNext",
5
- "target": "ES2023",
5
+ "target": "ES2022",
6
6
  "moduleResolution": "NodeNext",
7
7
  "outDir": "dist",
8
8
  "typeRoots": ["node_modules/@types"],