@rebasepro/utils 0.0.1-canary.eae7889 → 0.0.1-canary.eb08332
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/LICENSE +21 -6
- package/README.md +108 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.es.js +504 -528
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +631 -588
- package/dist/index.umd.js.map +1 -1
- package/dist/objects.d.ts +7 -1
- package/dist/strings.d.ts +2 -2
- package/package.json +17 -20
- package/src/fields.ts +0 -1
- package/src/flatten_object.ts +5 -1
- package/src/index.ts +0 -1
- package/src/objects.ts +73 -30
- package/src/strings.ts +7 -5
package/LICENSE
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rebase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# @rebasepro/utils
|
|
2
|
+
|
|
3
|
+
Shared utility functions used across the Rebase ecosystem.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @rebasepro/utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## What This Package Does
|
|
12
|
+
|
|
13
|
+
A zero-dependency\* collection of pure utility functions for string manipulation, deep object operations, pluralization, hashing, and more. Used internally by most Rebase packages.
|
|
14
|
+
|
|
15
|
+
\*Runtime dependency: `object-hash` (for `getHashValue`). Peer dependency: `@rebasepro/types`.
|
|
16
|
+
|
|
17
|
+
## Key Exports
|
|
18
|
+
|
|
19
|
+
### Strings (`strings`)
|
|
20
|
+
|
|
21
|
+
| Export | Description |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `toKebabCase(str)` | `"myString"` → `"my-string"` |
|
|
24
|
+
| `toSnakeCase(str)` | `"myString"` → `"my_string"` |
|
|
25
|
+
| `camelCase(str)` | `"my-string"` → `"myString"` |
|
|
26
|
+
| `slugify(text, separator?, lowercase?)` | URL/DB-safe slug. Default separator: `"_"` |
|
|
27
|
+
| `unslugify(slug)` | `"my_slug"` → `"My Slug"` |
|
|
28
|
+
| `prettifyIdentifier(input)` | `"imageURL"` → `"Image URL"`, `"my_field"` → `"My Field"` |
|
|
29
|
+
| `randomString(length?)` | Random alphanumeric string. Default length: 5 |
|
|
30
|
+
| `randomColor()` | Random hex color string |
|
|
31
|
+
|
|
32
|
+
### Objects (`objects`)
|
|
33
|
+
|
|
34
|
+
| Export | Description |
|
|
35
|
+
|---|---|
|
|
36
|
+
| `getIn(obj, path, default?)` | Deep-get by dot/bracket path: `getIn(obj, "a.b[0].c")` |
|
|
37
|
+
| `setIn(obj, path, value)` | Immutable deep-set by path |
|
|
38
|
+
| `clone(value)` | Shallow clone (arrays, plain objects) |
|
|
39
|
+
| `deepClone(value)` | Deep clone preserving functions and class instances |
|
|
40
|
+
| `mergeDeep(target, source, ignoreUndefined?)` | Deep merge with array-aware recursion, preserves class instances |
|
|
41
|
+
| `pick(obj, ...keys)` | Pick specified keys from an object |
|
|
42
|
+
| `isObject(item)` | Check if value is a non-null, non-array object |
|
|
43
|
+
| `isPlainObject(obj)` | Check if value is a plain `{}` object (not a class instance) |
|
|
44
|
+
| `getValueInPath(obj, path)` | Deep-get with array index support |
|
|
45
|
+
| `removeInPath(obj, path)` | Immutably remove a key at a nested path |
|
|
46
|
+
| `removeFunctions(obj)` | Strip all function values from an object tree |
|
|
47
|
+
| `removeUndefined(value, removeEmptyStrings?)` | Strip `undefined` values (and optionally empty strings) |
|
|
48
|
+
| `removeNulls(value)` | Strip `null` values recursively |
|
|
49
|
+
| `removePropsIfExisting(source, comparison)` | Remove properties from source that match comparison |
|
|
50
|
+
| `isEmptyObject(obj)` | Check if a plain object has no keys |
|
|
51
|
+
| `getHashValue(value)` | Hash any value using `object-hash` |
|
|
52
|
+
| `isEmptyArray`, `isFunction`, `isInteger`, `isNaN` | Type-check helpers |
|
|
53
|
+
|
|
54
|
+
### Arrays (`arrays`)
|
|
55
|
+
|
|
56
|
+
| Export | Description |
|
|
57
|
+
|---|---|
|
|
58
|
+
| `toArray(input)` | Normalize a value to an array: `T \| T[]` → `T[]` |
|
|
59
|
+
|
|
60
|
+
### Dates (`dates`)
|
|
61
|
+
|
|
62
|
+
| Export | Description |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `defaultDateFormat` | `"MMMM dd, yyyy, HH:mm:ss"` |
|
|
65
|
+
|
|
66
|
+
### Hash (`hash`)
|
|
67
|
+
|
|
68
|
+
| Export | Description |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `hashString(str)` | Fast 32-bit integer hash of a string |
|
|
71
|
+
|
|
72
|
+
### RegExp (`regexp`)
|
|
73
|
+
|
|
74
|
+
| Export | Description |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `serializeRegExp(input)` | Serialize a `RegExp` to string |
|
|
77
|
+
| `hydrateRegExp(input)` | Parse a string back to `RegExp` |
|
|
78
|
+
| `isValidRegExp(input)` | Check if a string is a valid regular expression |
|
|
79
|
+
|
|
80
|
+
### Flatten (`flatten_object`)
|
|
81
|
+
|
|
82
|
+
| Export | Description |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `flattenObject(obj, parentKey?)` | Flatten nested object to dot-notation keys: `{ a: { b: 1 } }` → `{ "a.b": 1 }` |
|
|
85
|
+
| `getArrayValuesCount(array)` | Map nested array paths to their maximum lengths across an array of objects |
|
|
86
|
+
|
|
87
|
+
### Plurals (`plurals`)
|
|
88
|
+
|
|
89
|
+
| Export | Description |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `plural(word, amount?)` | English pluralization with irregular/uncountable support |
|
|
92
|
+
| `singular(word, amount?)` | English singularization with irregular/uncountable support |
|
|
93
|
+
|
|
94
|
+
### Names (`names`)
|
|
95
|
+
|
|
96
|
+
| Export | Description |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `generateForeignKeyName(name)` | `"users"` → `"user_id"`, `"Product"` → `"product_id"` |
|
|
99
|
+
|
|
100
|
+
### Fields (`fields`)
|
|
101
|
+
|
|
102
|
+
| Export | Description |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `isDefaultFieldConfigId(id)` | Check if a field config ID is one of the built-in types (text_field, number_input, file_upload, etc.) |
|
|
105
|
+
|
|
106
|
+
## Related Packages
|
|
107
|
+
|
|
108
|
+
- `@rebasepro/types` — Type definitions used by some utility functions (`GeoPoint`)
|