@rebasepro/utils 0.3.0 → 0.5.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.
Files changed (2) hide show
  1. package/README.md +108 -0
  2. package/package.json +2 -2
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`)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rebasepro/utils",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.5.0",
5
5
  "description": "Utility functions for Rebase",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/rebaseco"
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "object-hash": "^3.0.0",
43
- "@rebasepro/types": "0.3.0"
43
+ "@rebasepro/types": "0.5.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@jest/globals": "^29.7.0",