@warp-drive/utilities 5.6.0-alpha.11

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.
Files changed (87) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +23 -0
  3. package/README.md +54 -0
  4. package/addon-main.cjs +5 -0
  5. package/declarations/-private/active-record/find-record.d.ts +66 -0
  6. package/declarations/-private/active-record/find-record.d.ts.map +1 -0
  7. package/declarations/-private/active-record/query.d.ts +54 -0
  8. package/declarations/-private/active-record/query.d.ts.map +1 -0
  9. package/declarations/-private/active-record/save-record.d.ts +144 -0
  10. package/declarations/-private/active-record/save-record.d.ts.map +1 -0
  11. package/declarations/-private/builder-utils.d.ts +5 -0
  12. package/declarations/-private/builder-utils.d.ts.map +1 -0
  13. package/declarations/-private/handlers/auto-compress.d.ts +153 -0
  14. package/declarations/-private/handlers/auto-compress.d.ts.map +1 -0
  15. package/declarations/-private/json-api/-utils.d.ts +110 -0
  16. package/declarations/-private/json-api/-utils.d.ts.map +1 -0
  17. package/declarations/-private/json-api/find-record.d.ts +66 -0
  18. package/declarations/-private/json-api/find-record.d.ts.map +1 -0
  19. package/declarations/-private/json-api/find-record.type-test.d.ts +2 -0
  20. package/declarations/-private/json-api/find-record.type-test.d.ts.map +1 -0
  21. package/declarations/-private/json-api/query.d.ts +104 -0
  22. package/declarations/-private/json-api/query.d.ts.map +1 -0
  23. package/declarations/-private/json-api/query.type-test.d.ts +2 -0
  24. package/declarations/-private/json-api/query.type-test.d.ts.map +1 -0
  25. package/declarations/-private/json-api/save-record.d.ts +191 -0
  26. package/declarations/-private/json-api/save-record.d.ts.map +1 -0
  27. package/declarations/-private/json-api/serialize.d.ts +57 -0
  28. package/declarations/-private/json-api/serialize.d.ts.map +1 -0
  29. package/declarations/-private/rest/find-record.d.ts +66 -0
  30. package/declarations/-private/rest/find-record.d.ts.map +1 -0
  31. package/declarations/-private/rest/query.d.ts +54 -0
  32. package/declarations/-private/rest/query.d.ts.map +1 -0
  33. package/declarations/-private/rest/save-record.d.ts +144 -0
  34. package/declarations/-private/rest/save-record.d.ts.map +1 -0
  35. package/declarations/-private/string/inflect.d.ts +105 -0
  36. package/declarations/-private/string/inflect.d.ts.map +1 -0
  37. package/declarations/-private/string/inflections.d.ts +10 -0
  38. package/declarations/-private/string/inflections.d.ts.map +1 -0
  39. package/declarations/-private/string/transform.d.ts +89 -0
  40. package/declarations/-private/string/transform.d.ts.map +1 -0
  41. package/declarations/-private.d.ts +2 -0
  42. package/declarations/-private.d.ts.map +1 -0
  43. package/declarations/active-record.d.ts +71 -0
  44. package/declarations/active-record.d.ts.map +1 -0
  45. package/declarations/handlers.d.ts +8 -0
  46. package/declarations/handlers.d.ts.map +1 -0
  47. package/declarations/index.d.ts +255 -0
  48. package/declarations/index.d.ts.map +1 -0
  49. package/declarations/json-api.d.ts +51 -0
  50. package/declarations/json-api.d.ts.map +1 -0
  51. package/declarations/rest.d.ts +51 -0
  52. package/declarations/rest.d.ts.map +1 -0
  53. package/declarations/string.d.ts +14 -0
  54. package/declarations/string.d.ts.map +1 -0
  55. package/dist/-private.js +7 -0
  56. package/dist/-private.js.map +1 -0
  57. package/dist/active-record.js +393 -0
  58. package/dist/active-record.js.map +1 -0
  59. package/dist/builder-utils-Donkk-BZ.js +22 -0
  60. package/dist/builder-utils-Donkk-BZ.js.map +1 -0
  61. package/dist/handlers.js +141 -0
  62. package/dist/handlers.js.map +1 -0
  63. package/dist/index.js +403 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/inflect-C1laviCe.js +376 -0
  66. package/dist/inflect-C1laviCe.js.map +1 -0
  67. package/dist/json-api.js +671 -0
  68. package/dist/json-api.js.map +1 -0
  69. package/dist/rest.js +393 -0
  70. package/dist/rest.js.map +1 -0
  71. package/dist/string.js +1 -0
  72. package/dist/string.js.map +1 -0
  73. package/logos/NCC-1701-a-blue.svg +4 -0
  74. package/logos/NCC-1701-a-gold.svg +4 -0
  75. package/logos/NCC-1701-a-gold_100.svg +1 -0
  76. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  77. package/logos/NCC-1701-a.svg +4 -0
  78. package/logos/README.md +4 -0
  79. package/logos/docs-badge.svg +2 -0
  80. package/logos/ember-data-logo-dark.svg +12 -0
  81. package/logos/ember-data-logo-light.svg +12 -0
  82. package/logos/github-header.svg +444 -0
  83. package/logos/social1.png +0 -0
  84. package/logos/social2.png +0 -0
  85. package/logos/warp-drive-logo-dark.svg +4 -0
  86. package/logos/warp-drive-logo-gold.svg +4 -0
  87. package/package.json +68 -0
@@ -0,0 +1,255 @@
1
+ import type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from '@warp-drive/core/types/params';
2
+ /**
3
+ * Simple utility function to assist in url building,
4
+ * query params, and other common request operations.
5
+ *
6
+ * These primitives may be used directly or composed
7
+ * by request builders to provide a consistent interface
8
+ * for building requests.
9
+ *
10
+ * For instance:
11
+ *
12
+ * ```ts
13
+ * import { buildBaseURL, buildQueryParams } from '@ember-data/request-utils';
14
+ *
15
+ * const baseURL = buildBaseURL({
16
+ * host: 'https://api.example.com',
17
+ * namespace: 'api/v1',
18
+ * resourcePath: 'emberDevelopers',
19
+ * op: 'query',
20
+ * identifier: { type: 'ember-developer' }
21
+ * });
22
+ * const url = `${baseURL}?${buildQueryParams({ name: 'Chris', include:['pets'] })}`;
23
+ * // => 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris'
24
+ * ```
25
+ *
26
+ * This is useful, but not as useful as the REST request builder for query which is sugar
27
+ * over this (and more!):
28
+ *
29
+ * ```ts
30
+ * import { query } from '@ember-data/rest/request';
31
+ *
32
+ * const options = query('ember-developer', { name: 'Chris', include:['pets'] });
33
+ * // => { url: 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' }
34
+ * // Note: options will also include other request options like headers, method, etc.
35
+ * ```
36
+ *
37
+ * @module
38
+ * @public
39
+ */
40
+ export interface BuildURLConfig {
41
+ host: string | null;
42
+ namespace: string | null;
43
+ }
44
+ /**
45
+ * Sets the global configuration for `buildBaseURL`
46
+ * for host and namespace values for the application.
47
+ *
48
+ * These values may still be overridden by passing
49
+ * them to buildBaseURL directly.
50
+ *
51
+ * This method may be called as many times as needed.
52
+ * host values of `''` or `'/'` are equivalent.
53
+ *
54
+ * Except for the value of `/` as host, host should not
55
+ * end with `/`.
56
+ *
57
+ * namespace should not start or end with a `/`.
58
+ *
59
+ * ```ts
60
+ * type BuildURLConfig = {
61
+ * host: string;
62
+ * namespace: string'
63
+ * }
64
+ * ```
65
+ *
66
+ * Example:
67
+ *
68
+ * ```ts
69
+ * import { setBuildURLConfig } from '@ember-data/request-utils';
70
+ *
71
+ * setBuildURLConfig({
72
+ * host: 'https://api.example.com',
73
+ * namespace: 'api/v1'
74
+ * });
75
+ * ```
76
+ *
77
+ * @public
78
+ * @param {BuildURLConfig} config
79
+ * @return {void}
80
+ */
81
+ export declare function setBuildURLConfig(config: BuildURLConfig): void;
82
+ export interface FindRecordUrlOptions {
83
+ op: 'findRecord';
84
+ identifier: {
85
+ type: string;
86
+ id: string;
87
+ };
88
+ resourcePath?: string;
89
+ host?: string;
90
+ namespace?: string;
91
+ }
92
+ export interface QueryUrlOptions {
93
+ op: 'query';
94
+ identifier: {
95
+ type: string;
96
+ };
97
+ resourcePath?: string;
98
+ host?: string;
99
+ namespace?: string;
100
+ }
101
+ export interface FindManyUrlOptions {
102
+ op: 'findMany';
103
+ identifiers: {
104
+ type: string;
105
+ id: string;
106
+ }[];
107
+ resourcePath?: string;
108
+ host?: string;
109
+ namespace?: string;
110
+ }
111
+ export interface FindRelatedCollectionUrlOptions {
112
+ op: 'findRelatedCollection';
113
+ identifier: {
114
+ type: string;
115
+ id: string;
116
+ };
117
+ fieldPath: string;
118
+ resourcePath?: string;
119
+ host?: string;
120
+ namespace?: string;
121
+ }
122
+ export interface FindRelatedResourceUrlOptions {
123
+ op: 'findRelatedRecord';
124
+ identifier: {
125
+ type: string;
126
+ id: string;
127
+ };
128
+ fieldPath: string;
129
+ resourcePath?: string;
130
+ host?: string;
131
+ namespace?: string;
132
+ }
133
+ export interface CreateRecordUrlOptions {
134
+ op: 'createRecord';
135
+ identifier: {
136
+ type: string;
137
+ };
138
+ resourcePath?: string;
139
+ host?: string;
140
+ namespace?: string;
141
+ }
142
+ export interface UpdateRecordUrlOptions {
143
+ op: 'updateRecord';
144
+ identifier: {
145
+ type: string;
146
+ id: string;
147
+ };
148
+ resourcePath?: string;
149
+ host?: string;
150
+ namespace?: string;
151
+ }
152
+ export interface DeleteRecordUrlOptions {
153
+ op: 'deleteRecord';
154
+ identifier: {
155
+ type: string;
156
+ id: string;
157
+ };
158
+ resourcePath?: string;
159
+ host?: string;
160
+ namespace?: string;
161
+ }
162
+ export interface GenericUrlOptions {
163
+ resourcePath: string;
164
+ host?: string;
165
+ namespace?: string;
166
+ }
167
+ export type UrlOptions = FindRecordUrlOptions | QueryUrlOptions | FindManyUrlOptions | FindRelatedCollectionUrlOptions | FindRelatedResourceUrlOptions | CreateRecordUrlOptions | UpdateRecordUrlOptions | DeleteRecordUrlOptions | GenericUrlOptions;
168
+ /**
169
+ * Builds a URL for a request based on the provided options.
170
+ * Does not include support for building query params (see `buildQueryParams`)
171
+ * so that it may be composed cleanly with other query-params strategies.
172
+ *
173
+ * Usage:
174
+ *
175
+ * ```ts
176
+ * import { buildBaseURL } from '@ember-data/request-utils';
177
+ *
178
+ * const url = buildBaseURL({
179
+ * host: 'https://api.example.com',
180
+ * namespace: 'api/v1',
181
+ * resourcePath: 'emberDevelopers',
182
+ * op: 'query',
183
+ * identifier: { type: 'ember-developer' }
184
+ * });
185
+ *
186
+ * // => 'https://api.example.com/api/v1/emberDevelopers'
187
+ * ```
188
+ *
189
+ * On the surface this may seem like a lot of work to do something simple, but
190
+ * it is designed to be composable with other utilities and interfaces that the
191
+ * average product engineer will never need to see or use.
192
+ *
193
+ * A few notes:
194
+ *
195
+ * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.
196
+ * - `host` and `namespace` are optional, but if they are not provided, the values globally
197
+ * configured via `setBuildURLConfig` will be used.
198
+ * - `op` is required and must be one of the following:
199
+ * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'
200
+ * - Depending on the value of `op`, `identifier` or `identifiers` will be required.
201
+ *
202
+ * @public
203
+ * @param urlOptions
204
+ * @return {String}
205
+ */
206
+ export declare function buildBaseURL(urlOptions: UrlOptions): string;
207
+ /**
208
+ * filter out keys of an object that have falsy values or point to empty arrays
209
+ * returning a new object with only those keys that have truthy values / non-empty arrays
210
+ *
211
+ * @public
212
+ * @param {Record<string, Serializable>} source object to filter keys with empty values from
213
+ * @return {Record<string, Serializable>} A new object with the keys that contained empty values removed
214
+ */
215
+ export declare function filterEmpty(source: Record<string, Serializable>): Record<string, Serializable>;
216
+ /**
217
+ * Sorts query params by both key and value returning a new URLSearchParams
218
+ * object with the keys inserted in sorted order.
219
+ *
220
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
221
+ *
222
+ * Options:
223
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
224
+ *
225
+ * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2`
226
+ * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2`
227
+ * 'repeat': appends the key for every value e.g. `&ids=1&ids=2`
228
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
229
+ *
230
+ * @public
231
+ * @param {URLSearchParams | object} params
232
+ * @param {Object} options
233
+ * @return {URLSearchParams} A URLSearchParams with keys inserted in sorted order
234
+ */
235
+ export declare function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams;
236
+ /**
237
+ * Sorts query params by both key and value, returning a query params string
238
+ *
239
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
240
+ *
241
+ * Options:
242
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
243
+ *
244
+ * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
245
+ * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
246
+ * 'repeat': appends the key for every value e.g. `ids=1&ids=2`
247
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
248
+ *
249
+ * @public
250
+ * @param {URLSearchParams | Object} params
251
+ * @param {Object} [options]
252
+ * @return {String} A sorted query params string without the leading `?`
253
+ */
254
+ export declare function buildQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string;
255
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAEtH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAMH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,QAsBvD;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,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EAAE,+BAA+B,GAAG,MAAM,CAE7G"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ This package provides utilities for working with [JSON:API](https://json-api.org) APIs with [*Ember***Data**](https://github.com/emberjs/data/).
3
+
4
+ ## Installation
5
+
6
+ Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
7
+
8
+ ```no-highlight
9
+ pnpm add @ember-data/json-api
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ Request builders are functions that produce [Fetch Options](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
15
+ They take a few contextual inputs about the request you want to make, abstracting away the gnarlier details.
16
+
17
+ For instance, to fetch a resource from your API
18
+
19
+ ```ts
20
+ import { findRecord } from '@ember-data/json-api/request';
21
+
22
+ const options = findRecord('ember-developer', '1', { include: ['pets', 'friends'] });
23
+
24
+ /*
25
+ {
26
+ url: 'https://api.example.com/v1/ember-developers/1?include=friends,pets',
27
+ method: 'GET',
28
+ headers: <Headers>,
29
+ // => 'Accept': 'application/vnd.api+json'
30
+ // => 'Content-Type': 'application/vnd.api+json'
31
+ op: 'findRecord';
32
+ records: [{ type: 'ember-developer', id: '1' }]
33
+ }
34
+ *\
35
+ ```
36
+
37
+ Request builder output may be used with either `requestManager.request` or `store.request`.
38
+
39
+ URLs are stable. The same query will produce the same URL every time, even if the order of keys in
40
+ the query or values in an array changes.
41
+
42
+ URLs follow the most common JSON:API format (dasherized pluralized resource types).
43
+ *
44
+ * @module
45
+ */
46
+ export { findRecord } from './-private/json-api/find-record';
47
+ export { query, postQuery } from './-private/json-api/query';
48
+ export { deleteRecord, createRecord, updateRecord } from './-private/json-api/save-record';
49
+ export { serializeResources, serializePatch } from './-private/json-api/serialize';
50
+ export { setBuildURLConfig } from './-private/json-api/-utils';
51
+ //# sourceMappingURL=json-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-api.d.ts","sourceRoot":"","sources":["../src/json-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ This package provides utilities for working with **REST**ful APIs with [*Ember***Data**](https://github.com/emberjs/data/).
3
+
4
+ ## Installation
5
+
6
+ Install using your javascript package manager of choice. For instance with [pnpm](https://pnpm.io/)
7
+
8
+ ```no-highlight
9
+ pnpm add @ember-data/json-api
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ Request builders are functions that produce [Fetch Options](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
15
+ They take a few contextual inputs about the request you want to make, abstracting away the gnarlier details.
16
+
17
+ For instance, to fetch a resource from your API
18
+
19
+ ```ts
20
+ import { findRecord } from '@ember-data/rest/request';
21
+
22
+ const options = findRecord('ember-developer', '1', { include: ['pets', 'friends'] });
23
+
24
+ /*
25
+ => {
26
+ url: 'https://api.example.com/v1/emberDevelopers/1?include=friends,pets',
27
+ method: 'GET',
28
+ headers: <Headers>, // 'Content-Type': 'application/json;charset=utf-8'
29
+ op: 'findRecord';
30
+ records: [{ type: 'ember-developer', id: '1' }]
31
+ }
32
+ * /
33
+ ```
34
+
35
+ Request builder output is ready to go for use with [store.request](https://api.emberjs.com/ember-data/release/classes/Store/methods/request?anchor=request),
36
+ [manager.request](https://api.emberjs.com/ember-data/release/classes/RequestManager/methods/request?anchor=request) and most conventional REST APIs.
37
+
38
+ Resource types are pluralized and camelized for the url.
39
+
40
+ URLs are stable. The same query will produce the same URL every time, even if the order of keys in
41
+ the query or values in an array changes.
42
+
43
+ URLs follow the most common REST format (camelCase pluralized resource types).
44
+
45
+ * @module
46
+ * @public
47
+ */
48
+ export { findRecord } from './-private/rest/find-record';
49
+ export { query } from './-private/rest/query';
50
+ export { deleteRecord, createRecord, updateRecord } from './-private/rest/save-record';
51
+ //# sourceMappingURL=rest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * String utilties for transforming and inflecting strings useful for
3
+ * when the format provided by the server is not the format you want to use
4
+ * in your application.
5
+ *
6
+ * Each transformation function stores its results in an LRUCache to avoid
7
+ * recomputing the same value multiple times. The cache size can be set
8
+ * using the `setMaxLRUCacheSize` function. The default size is 10,000.
9
+ *
10
+ * @module
11
+ */
12
+ export { pluralize, singularize, singular, plural, loadIrregular, loadUncountable, irregular, uncountable, resetToDefaults, clear, clearRules, } from './-private/string/inflect.ts';
13
+ export { dasherize, camelize, capitalize, underscore, setMaxLRUCacheSize } from './-private/string/transform.ts';
14
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,SAAS,EACT,WAAW,EACX,QAAQ,EACR,MAAM,EACN,aAAa,EACb,eAAe,EACf,SAAS,EACT,WAAW,EACX,eAAe,EACf,KAAK,EACL,UAAU,GACX,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,7 @@
1
+ const defaultRules = {
2
+ plurals: [[/$/, 's'], [/s$/i, 's'], [/^(ax|test)is$/i, '$1es'], [/(octop|vir)us$/i, '$1i'], [/(octop|vir)i$/i, '$1i'], [/(alias|status|bonus)$/i, '$1es'], [/(bu)s$/i, '$1ses'], [/(buffal|tomat)o$/i, '$1oes'], [/([ti])um$/i, '$1a'], [/([ti])a$/i, '$1a'], [/sis$/i, 'ses'], [/(?:([^f])fe|([lr])f)$/i, '$1$2ves'], [/(hive)$/i, '$1s'], [/([^aeiouy]|qu)y$/i, '$1ies'], [/(x|ch|ss|sh)$/i, '$1es'], [/(matr|vert|ind)(?:ix|ex)$/i, '$1ices'], [/^(m|l)ouse$/i, '$1ice'], [/^(m|l)ice$/i, '$1ice'], [/^(ox)$/i, '$1en'], [/^(oxen)$/i, '$1'], [/(quiz)$/i, '$1zes']],
3
+ singular: [[/s$/i, ''], [/(ss)$/i, '$1'], [/(n)ews$/i, '$1ews'], [/([ti])a$/i, '$1um'], [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1sis'], [/(^analy)(sis|ses)$/i, '$1sis'], [/([^f])ves$/i, '$1fe'], [/(hive)s$/i, '$1'], [/(tive)s$/i, '$1'], [/([lr])ves$/i, '$1f'], [/([^aeiouy]|qu)ies$/i, '$1y'], [/(s)eries$/i, '$1eries'], [/(m)ovies$/i, '$1ovie'], [/(x|ch|ss|sh)es$/i, '$1'], [/^(m|l)ice$/i, '$1ouse'], [/(bus)(es)?$/i, '$1'], [/(o)es$/i, '$1'], [/(shoe)s$/i, '$1'], [/(cris|test)(is|es)$/i, '$1is'], [/^(a)x[ie]s$/i, '$1xis'], [/(octop|vir)(us|i)$/i, '$1us'], [/(alias|status|bonus)(es)?$/i, '$1'], [/^(ox)en/i, '$1'], [/(vert|ind)ices$/i, '$1ex'], [/(matr)ices$/i, '$1ix'], [/(quiz)zes$/i, '$1'], [/(database)s$/i, '$1']],
4
+ irregularPairs: [['person', 'people'], ['man', 'men'], ['child', 'children'], ['sex', 'sexes'], ['move', 'moves'], ['cow', 'kine'], ['zombie', 'zombies']],
5
+ uncountable: ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'police']
6
+ };
7
+ export { defaultRules as InflectionRuleDefaults };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"-private.js","sources":["../src/-private/string/inflections.ts"],"sourcesContent":["export type RulesArray = Array<[RegExp, string]>;\ntype DefaultRulesType = {\n plurals: RulesArray;\n singular: RulesArray;\n irregularPairs: Array<[string, string]>;\n uncountable: string[];\n};\n\nexport const defaultRules: DefaultRulesType = {\n plurals: [\n [/$/, 's'],\n [/s$/i, 's'],\n [/^(ax|test)is$/i, '$1es'],\n [/(octop|vir)us$/i, '$1i'],\n [/(octop|vir)i$/i, '$1i'],\n [/(alias|status|bonus)$/i, '$1es'],\n [/(bu)s$/i, '$1ses'],\n [/(buffal|tomat)o$/i, '$1oes'],\n [/([ti])um$/i, '$1a'],\n [/([ti])a$/i, '$1a'],\n [/sis$/i, 'ses'],\n [/(?:([^f])fe|([lr])f)$/i, '$1$2ves'],\n [/(hive)$/i, '$1s'],\n [/([^aeiouy]|qu)y$/i, '$1ies'],\n [/(x|ch|ss|sh)$/i, '$1es'],\n [/(matr|vert|ind)(?:ix|ex)$/i, '$1ices'],\n [/^(m|l)ouse$/i, '$1ice'],\n [/^(m|l)ice$/i, '$1ice'],\n [/^(ox)$/i, '$1en'],\n [/^(oxen)$/i, '$1'],\n [/(quiz)$/i, '$1zes'],\n ],\n\n singular: [\n [/s$/i, ''],\n [/(ss)$/i, '$1'],\n [/(n)ews$/i, '$1ews'],\n [/([ti])a$/i, '$1um'],\n [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1sis'],\n [/(^analy)(sis|ses)$/i, '$1sis'],\n [/([^f])ves$/i, '$1fe'],\n [/(hive)s$/i, '$1'],\n [/(tive)s$/i, '$1'],\n [/([lr])ves$/i, '$1f'],\n [/([^aeiouy]|qu)ies$/i, '$1y'],\n [/(s)eries$/i, '$1eries'],\n [/(m)ovies$/i, '$1ovie'],\n [/(x|ch|ss|sh)es$/i, '$1'],\n [/^(m|l)ice$/i, '$1ouse'],\n [/(bus)(es)?$/i, '$1'],\n [/(o)es$/i, '$1'],\n [/(shoe)s$/i, '$1'],\n [/(cris|test)(is|es)$/i, '$1is'],\n [/^(a)x[ie]s$/i, '$1xis'],\n [/(octop|vir)(us|i)$/i, '$1us'],\n [/(alias|status|bonus)(es)?$/i, '$1'],\n [/^(ox)en/i, '$1'],\n [/(vert|ind)ices$/i, '$1ex'],\n [/(matr)ices$/i, '$1ix'],\n [/(quiz)zes$/i, '$1'],\n [/(database)s$/i, '$1'],\n ],\n\n irregularPairs: [\n ['person', 'people'],\n ['man', 'men'],\n ['child', 'children'],\n ['sex', 'sexes'],\n ['move', 'moves'],\n ['cow', 'kine'],\n ['zombie', 'zombies'],\n ],\n\n uncountable: ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'police'],\n};\n"],"names":["defaultRules","plurals","singular","irregularPairs","uncountable"],"mappings":"AAQO,MAAMA,YAA8B,GAAG;AAC5CC,EAAAA,OAAO,EAAE,CACP,CAAC,GAAG,EAAE,GAAG,CAAC,EACV,CAAC,KAAK,EAAE,GAAG,CAAC,EACZ,CAAC,gBAAgB,EAAE,MAAM,CAAC,EAC1B,CAAC,iBAAiB,EAAE,KAAK,CAAC,EAC1B,CAAC,gBAAgB,EAAE,KAAK,CAAC,EACzB,CAAC,wBAAwB,EAAE,MAAM,CAAC,EAClC,CAAC,SAAS,EAAE,OAAO,CAAC,EACpB,CAAC,mBAAmB,EAAE,OAAO,CAAC,EAC9B,CAAC,YAAY,EAAE,KA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