@budsbox/lib-es 1.0.1 → 2.1.0

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/string.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { CamelCase, DelimiterCase, KebabCase, PascalCase, SnakeCase } from 'type-fest';
2
- import type { Nil } from '@budsbox/lib-types';
2
+ import type { Nil, Undef } from '@budsbox/lib-types';
3
3
  import type { ParsedPackageName } from './types.js';
4
4
  export type { ParsedPackageName };
5
5
  /**
@@ -16,7 +16,7 @@ export declare function parsePackageName(packageName: string, clean?: boolean):
16
16
  * @param parsedPackageName - An object representing the parsed package name with fields such as `scope` and `name`.
17
17
  * @returns The string representation of the package name, including the scope if it exists.
18
18
  */
19
- export declare function stringifyPackageName(parsedPackageName: Readonly<ParsedPackageName>): string;
19
+ export declare function serializePackageName(parsedPackageName: Readonly<ParsedPackageName>): string;
20
20
  /**
21
21
  * Converts a parsed package name object or a Nil value into a string representation.
22
22
  *
@@ -24,7 +24,22 @@ export declare function stringifyPackageName(parsedPackageName: Readonly<ParsedP
24
24
  * @param allowNil - A boolean flag specifying whether Nil values are allowed for conversion.
25
25
  * @returns The string representation of the package name if valid, or an empty string if `allowNil` is true and the input is Nil.
26
26
  */
27
- export declare function stringifyPackageName(parsedPackageName: Readonly<ParsedPackageName> | Nil, allowNil: true): string;
27
+ export declare function serializePackageName(parsedPackageName: Readonly<ParsedPackageName> | Nil, allowNil: true): string;
28
+ /**
29
+ * Resolves the package name based on the provided identifier and options.
30
+ * Can return either a string representing the package name or a parsed package name object.
31
+ *
32
+ * @param ident - The package identifier, either as a string or a parsed package name object.
33
+ * @param options - Optional settings to modify the resolution behavior.
34
+ * Includes an optional `baseScope` to use as a default scope and a `parsed` flag
35
+ * to indicate whether the result should be returned as a parsed package name object.
36
+ * @returns The resolved package name as a string if `parsed` is false or not specified,
37
+ * or as a `ParsedPackageName` object if `parsed` is true.
38
+ */
39
+ export declare function resolvePackageName<TParsed extends boolean = false>(ident: string | Readonly<ParsedPackageName>, options?: Readonly<{
40
+ baseScope?: Undef<string>;
41
+ parsed?: TParsed;
42
+ }>): TParsed extends true ? ParsedPackageName : string;
28
43
  /**
29
44
  * Converts the provided value to a string representation suitable for debugging purposes.
30
45
  *
package/dist/string.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isNil, isNotNil } from '#guards';
1
+ import { isNil, isNotNil, isString } from './guards.js';
2
2
  /**
3
3
  * Parses a package name string to extract its scope and name.
4
4
  *
@@ -13,13 +13,21 @@ export function parsePackageName(packageName, clean = false) {
13
13
  name: packageName.replace(scope ?? '', ''),
14
14
  };
15
15
  }
16
- export function stringifyPackageName(parsedPackageName, allowNil = false) {
16
+ export function serializePackageName(parsedPackageName, allowNil = false) {
17
17
  if (!allowNil && isNil(parsedPackageName)) {
18
18
  throw new TypeError('Expected a non-nil value');
19
19
  }
20
20
  const { scope, name } = parsedPackageName ?? { scope: null, name: '' };
21
21
  return joinPath(scope?.replace(/^@?/, '@'), name);
22
22
  }
23
+ export function resolvePackageName(ident, { baseScope, parsed = false, } = {}) {
24
+ const { scope, name } = isString(ident) ? parsePackageName(ident) : ident;
25
+ const parsedIdent = {
26
+ scope: scope ?? baseScope ?? null,
27
+ name,
28
+ };
29
+ return parsed ? parsedIdent : serializePackageName(parsedIdent);
30
+ }
23
31
  /**
24
32
  * Converts the provided value to a string representation suitable for debugging purposes.
25
33
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budsbox/lib-es",
3
- "version": "1.0.1",
3
+ "version": "2.1.0",
4
4
  "homepage": "https://gitlab.com/budsbox/fe/seed",
5
5
  "bugs": {
6
6
  "url": "https://gitlab.com/budsbox/fe/seed/-/issues"
@@ -129,10 +129,10 @@
129
129
  "type-fest": "^4.32.0"
130
130
  },
131
131
  "devDependencies": {
132
- "@budsbox/eslint": "^1.0.3",
132
+ "@budsbox/eslint": "^1.1.0",
133
133
  "@budsbox/eslint_presets-lib": "^1.0.2",
134
134
  "@budsbox/eslint_presets-tools": "^1.0.2",
135
- "@budsbox/tsconfigs": "^4.1.0",
135
+ "@budsbox/tsconfigs": "^4.2.0",
136
136
  "@eslint/js": "^9.26.0",
137
137
  "@types/eslint": "^9.6.1",
138
138
  "@types/node": "^22.15.2",