@tolki/types 1.11.0 → 1.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/types",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "Utility TypeScript types for @tolki packages and Laravel HTTP responses.",
5
5
  "author": "Abraham Arango <https://github.com/abetwothree>",
6
6
  "license": "MIT",
@@ -58,7 +58,16 @@
58
58
  "types": "./src/path-resolve.d.ts"
59
59
  },
60
60
  "./responses": {
61
- "types": "./src/responses.d.ts"
61
+ "types": "./src/resource-responses.d.ts"
62
+ },
63
+ "./resource-responses": {
64
+ "types": "./src/resource-responses.d.ts"
65
+ },
66
+ "./json-api": {
67
+ "types": "./src/json-api.d.ts"
68
+ },
69
+ "./routes": {
70
+ "types": "./src/routes.d.ts"
62
71
  },
63
72
  "./strings": {
64
73
  "types": "./src/strings.d.ts"
package/src/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- export type * from "./arrays";
2
- export type * from "./collections";
3
- export type * from "./data";
4
- export type * from "./enums";
5
- export type * from "./json-api";
6
- export type * from "./lang";
7
- export type * from "./models";
8
- export type * from "./objects";
9
- export type * from "./pagination";
10
- export type * from "./path-resolve";
11
- export type * from "./resource-responses";
12
- export type * from "./routes";
13
- export type * from "./strings";
14
- export type * from "./utils";
1
+ export type * from "./arrays.js";
2
+ export type * from "./collections.js";
3
+ export type * from "./data.js";
4
+ export type * from "./enums.js";
5
+ export type * from "./json-api.js";
6
+ export type * from "./lang.js";
7
+ export type * from "./models.js";
8
+ export type * from "./objects.js";
9
+ export type * from "./pagination.js";
10
+ export type * from "./path-resolve.js";
11
+ export type * from "./resource-responses.js";
12
+ export type * from "./routes.js";
13
+ export type * from "./strings.js";
14
+ export type * from "./utils.js";
package/src/json-api.d.ts CHANGED
@@ -3,7 +3,7 @@ import type {
3
3
  JsonResourceLinks,
4
4
  JsonResourceMeta,
5
5
  JsonResourceSimpleMeta,
6
- } from "./resource-responses";
6
+ } from "./resource-responses.js";
7
7
 
8
8
  /**
9
9
  * A resource identifier object: how a relationship's `data` names a related resource.
package/src/lang.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import type { Countable } from "./data";
1
+ import type { Countable } from "./data.js";
2
2
  import type {
3
3
  ObjectDotPath,
4
4
  ObjectDotPathValue,
5
5
  ObjectResolvePath,
6
- } from "./path-resolve";
6
+ } from "./path-resolve.js";
7
+ import type { LocaleNormalizer } from "./utils.js";
7
8
 
8
9
  /** A tag callback receives the text between `<key>` and `</key>`. */
9
10
  type TagCallback = (children: string) => unknown;
@@ -251,6 +252,8 @@ interface LangOptions<TLines extends LangLines = LangLines> {
251
252
  readonly lines?: TLines;
252
253
  /** Fetches a locale's lines when it is first needed. */
253
254
  readonly load?: LocaleLinesLoader;
255
+ /** Converts every locale the lang is given, such as with `normalizeLocale`; unset uses each locale as given. */
256
+ readonly normalizeLocalesUsing?: LocaleNormalizer | null;
254
257
  }
255
258
 
256
259
  // An export list keeps the helpers above private: a .d.ts module without one exports every declaration.
package/src/objects.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ArrayInnerValue } from "./arrays";
2
- import type { KnownObjectKeys } from "./path-resolve";
1
+ import type { ArrayInnerValue } from "./arrays.js";
2
+ import type { KnownObjectKeys } from "./path-resolve.js";
3
3
 
4
4
  /**
5
5
  * Helper type to add a key-value pair to an object type
@@ -26,7 +26,7 @@ export type NonObjectItems =
26
26
  /**
27
27
  * `NonObjectItems` without the Map, for an obj helper's empty-result row, so `Map | string[]` is not typed as empty.
28
28
  *
29
- * @remarks A Map keyed by `unknown`, `any` or an object type still fits the `WeakMap` member, so a union
29
+ * @remarks A Map keyed by `any` or an object type still fits the `WeakMap` member, so a union
30
30
  * holding it beside another of these values is typed as empty, though its Map is walked.
31
31
  */
32
32
  export type NonKeyedItems = Exclude<
@@ -1,4 +1,4 @@
1
- import type { PaginatorLink } from "./pagination";
1
+ import type { PaginatorLink } from "./pagination.js";
2
2
 
3
3
  /**
4
4
  * The `meta` block of a resource collection paginated with `paginate()`.
package/src/strings.d.ts CHANGED
@@ -1,3 +1,29 @@
1
1
  export interface CanBeEscapedWhenCastToString {
2
2
  escapeWhenCastToString(escape: boolean): this;
3
3
  }
4
+
5
+ /**
6
+ * A subject Str's replace() and remove() accept: a string, strings in a list, Map, collection or iterable,
7
+ * or an object of strings.
8
+ */
9
+ export type StringSubject<TSubject> =
10
+ | string
11
+ | Iterable<string>
12
+ | ReadonlyMap<unknown, string>
13
+ | (object & { readonly [K in keyof TSubject]: string });
14
+
15
+ /**
16
+ * What replace() and remove() return for a subject: a string for a string, else the subject's shape holding
17
+ * strings.
18
+ */
19
+ export type StringSubjectResult<TSubject> = TSubject extends string
20
+ ? string
21
+ : TSubject extends ReadonlyMap<infer TKey, unknown>
22
+ ? Map<TKey, string>
23
+ : TSubject extends readonly unknown[]
24
+ ? string[]
25
+ : TSubject extends { all(): infer TItems }
26
+ ? StringSubjectResult<TItems>
27
+ : TSubject extends Iterable<unknown>
28
+ ? string[]
29
+ : { [K in keyof TSubject]: string };
package/src/utils.d.ts CHANGED
@@ -1 +1,4 @@
1
- export {};
1
+ /** Turns a locale into the spelling to use, such as `pt-BR` into `pt_BR`. */
2
+ type LocaleNormalizer = (locale: string) => string;
3
+
4
+ export type { LocaleNormalizer };