@active-record-ts/active-model 1.0.0 → 1.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/src/index.ts DELETED
@@ -1,59 +0,0 @@
1
- export {
2
- AttributeSet,
3
- Attributes,
4
- type AttributeDefinition,
5
- } from './AttributeSet';
6
- export {
7
- ABORT_SENTINEL,
8
- CallbackChain,
9
- HaltError,
10
- throwAbort,
11
- type AroundCallbackFn,
12
- type CallbackEvent,
13
- type CallbackFn,
14
- type CallbackKind,
15
- } from './Callbacks';
16
- export { BASE, ErrorObject, Errors, type ErrorEntry } from './Errors';
17
- export { Model, ValidationError, type TypeRef } from './Model';
18
- export {
19
- AcceptanceValidator,
20
- AbsenceValidator,
21
- ConfirmationValidator,
22
- ExclusionValidator,
23
- FormatValidator,
24
- InclusionValidator,
25
- LengthValidator,
26
- NumericalityValidator,
27
- PresenceValidator,
28
- StrictValidationFailed,
29
- type AcceptanceOptions,
30
- type ConfirmationOptions,
31
- type ExclusionOptions,
32
- type FormatOptions,
33
- type InclusionOptions,
34
- type LengthOptions,
35
- type NumericalityOptions,
36
- type ValidationContext,
37
- type Validator,
38
- type ValidatorOptions,
39
- } from './Validator';
40
- export {
41
- BigIntType,
42
- BinaryType,
43
- BooleanType,
44
- DateType,
45
- DateTimeType,
46
- DecimalType,
47
- FloatType,
48
- IntegerType,
49
- JSONType,
50
- StringType,
51
- ValueType,
52
- hasType,
53
- lookupType,
54
- registerType,
55
- valuesEqual,
56
- type Type,
57
- } from './Type';
58
- export { camelize, pluralize, tableize, underscore } from './inflector';
59
- export { Name } from './Name';
package/src/inflector.ts DELETED
@@ -1,74 +0,0 @@
1
- /**
2
- * Tiny inflector — enough to convert class names into Rails-style table
3
- * names (`User` -> `users`, `Person` -> `people`, `Octopus` -> `octopi`).
4
- * Not a substitute for a full inflector (no `inflect.rb` here); add cases
5
- * as needed.
6
- */
7
-
8
- const IRREGULAR: Array<[string, string]> = [
9
- ['person', 'people'],
10
- ['man', 'men'],
11
- ['woman', 'women'],
12
- ['child', 'children'],
13
- ['ox', 'oxen'],
14
- ['mouse', 'mice'],
15
- ['octopus', 'octopi'],
16
- ['cactus', 'cacti'],
17
- ['goose', 'geese'],
18
- ['foot', 'feet'],
19
- ['tooth', 'teeth'],
20
- ];
21
-
22
- const UNCOUNTABLE = new Set(['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep']);
23
-
24
- const PLURAL_RULES: Array<[RegExp, string]> = [
25
- [/(quiz)$/i, '$1zes'],
26
- [/^(ox)$/i, '$1en'],
27
- [/([m|l])ouse$/i, '$1ice'],
28
- [/(matr|vert|ind)ix|ex$/i, '$1ices'],
29
- [/(x|ch|ss|sh)$/i, '$1es'],
30
- [/([^aeiouy]|qu)y$/i, '$1ies'],
31
- [/(hive)$/i, '$1s'],
32
- [/(?:([^f])fe|([lr])f)$/i, '$1$2ves'],
33
- [/sis$/i, 'ses'],
34
- [/([ti])um$/i, '$1a'],
35
- [/(buffal|tomat)o$/i, '$1oes'],
36
- [/(bu)s$/i, '$1ses'],
37
- [/(alias|status)$/i, '$1es'],
38
- [/(octop|vir)us$/i, '$1i'],
39
- [/(ax|test)is$/i, '$1es'],
40
- [/s$/i, 's'],
41
- [/$/, 's'],
42
- ];
43
-
44
- export const pluralize = (word: string): string => {
45
- if (!word) return word;
46
- const lower = word.toLowerCase();
47
- if (UNCOUNTABLE.has(lower)) return word;
48
- for (const [singular, plural] of IRREGULAR) {
49
- if (lower === singular) return plural;
50
- if (lower === plural) return plural;
51
- }
52
- for (const [pattern, replacement] of PLURAL_RULES) {
53
- if (pattern.test(word)) return word.replace(pattern, replacement);
54
- }
55
- return `${word}s`;
56
- };
57
-
58
- export const underscore = (word: string): string =>
59
- word
60
- .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
61
- .replace(/([a-z\d])([A-Z])/g, '$1_$2')
62
- .replace(/-/g, '_')
63
- .toLowerCase();
64
-
65
- export const camelize = (word: string, lower = false): string => {
66
- const camel = word
67
- .split(/[_-]/)
68
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
69
- .join('');
70
- return lower ? camel.charAt(0).toLowerCase() + camel.slice(1) : camel;
71
- };
72
-
73
- /** Convert a class name into a Rails-style table name (`UserAccount` -> `user_accounts`). */
74
- export const tableize = (className: string): string => pluralize(underscore(className));