ts-object-lite 1.0.2 → 2.0.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 +5 -5
- package/LICENSE +0 -21
- package/README.md +0 -201
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/object.d.ts +0 -18
- package/dist/object.js +0 -100
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-object-lite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Lightweight, type-safe object utility library for web developers",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json"
|
|
20
|
+
},
|
|
18
21
|
"keywords": [
|
|
19
22
|
"utils",
|
|
20
23
|
"typescript",
|
|
@@ -23,8 +26,5 @@
|
|
|
23
26
|
"lite"
|
|
24
27
|
],
|
|
25
28
|
"author": "Gaurang Mody - G8X",
|
|
26
|
-
"license": "MIT"
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"typescript": "^6.0.2"
|
|
29
|
-
}
|
|
29
|
+
"license": "MIT"
|
|
30
30
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Gaurang Mody
|
|
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
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
# ngx-utils-lite
|
|
2
|
-
|
|
3
|
-
Everything you need, nothing you don't.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **String Utils** - slugify, camelCase, kebabCase, pascalCase, truncate, capitalize, titleCase, escapeHtml
|
|
8
|
-
- **Date Utils** - format, relative time, isToday, add, diff
|
|
9
|
-
- **Array Utils** - unique, chunk, groupBy, shuffle, compact
|
|
10
|
-
- **Object Utils** - deepGet, deepClone, merge, omit, pick, isEmpty
|
|
11
|
-
- **Number Utils** - formatCurrency, formatBytes, formatPercent, clamp, round, randomInt
|
|
12
|
-
- **Validation Utils** - isEmail, isUrl, isPhone, isPostalCode, isStrongPassword
|
|
13
|
-
- **ID Utils** - uuid, nanoid, shortId, hash, snowflake, generateCode
|
|
14
|
-
- **Cookie Utils** - get, set, delete, has
|
|
15
|
-
- **Copy to Clipboard** - Directive to copy text to clipboard on click
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm install ngx-utils-lite
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Usage
|
|
24
|
-
|
|
25
|
-
### String Utils
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { Injectable } from '@angular/core';
|
|
29
|
-
import { NgxStringUtils } from 'ngx-utils-lite';
|
|
30
|
-
|
|
31
|
-
@Injectable({ providedIn: 'root' })
|
|
32
|
-
export class MyService {
|
|
33
|
-
constructor(private str: NgxStringUtils) { }
|
|
34
|
-
|
|
35
|
-
myMethod(): void {
|
|
36
|
-
this.str.slugify('Hello World'); // 'hello-world'
|
|
37
|
-
this.str.camelCase('hello world'); // 'helloWorld'
|
|
38
|
-
this.str.truncate('Hello World', 10); // 'Hello W...'
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Date Utils
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
import { Injectable } from '@angular/core';
|
|
47
|
-
import { NgxDateUtils } from 'ngx-utils-lite';
|
|
48
|
-
|
|
49
|
-
@Injectable({ providedIn: 'root' })
|
|
50
|
-
export class MyService {
|
|
51
|
-
constructor(private date: NgxDateUtils) { }
|
|
52
|
-
|
|
53
|
-
myMethod(): void {
|
|
54
|
-
this.date.format(new Date(), 'YYYY-MM-DD'); // '2026-04-11'
|
|
55
|
-
this.date.relative(new Date(Date.now() - 3600000)); // '1 hour ago'
|
|
56
|
-
this.date.add(new Date(), 7, 'day'); // +7 days
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Array Utils
|
|
62
|
-
|
|
63
|
-
```typescript
|
|
64
|
-
import { Injectable } from '@angular/core';
|
|
65
|
-
import { NgxArrayUtils } from 'ngx-utils-lite';
|
|
66
|
-
|
|
67
|
-
@Injectable({ providedIn: 'root' })
|
|
68
|
-
export class MyService {
|
|
69
|
-
constructor(private arr: NgxArrayUtils) { }
|
|
70
|
-
|
|
71
|
-
myMethod(): void {
|
|
72
|
-
this.arr.unique([1, 2, 2, 3]); // [1, 2, 3]
|
|
73
|
-
this.arr.chunk([1, 2, 3, 4], 2); // [[1,2], [3,4]]
|
|
74
|
-
this.arr.groupBy(['apple', 'banana'], s => s[0]); // {a: ['apple'], b: ['banana']}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Object Utils
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
import { Injectable } from '@angular/core';
|
|
83
|
-
import { NgxObjectUtils } from 'ngx-utils-lite';
|
|
84
|
-
|
|
85
|
-
@Injectable({ providedIn: 'root' })
|
|
86
|
-
export class MyService {
|
|
87
|
-
constructor(private obj: NgxObjectUtils) { }
|
|
88
|
-
|
|
89
|
-
myMethod(): void {
|
|
90
|
-
this.obj.deepGet({a: {b: 42}}, 'a.b'); // 42
|
|
91
|
-
this.obj.deepClone({a: 1}); // {a: 1}
|
|
92
|
-
this.obj.merge({a: 1}, {b: 2}); // {a: 1, b: 2}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Number Utils
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
import { Injectable } from '@angular/core';
|
|
101
|
-
import { NgxNumberUtils } from 'ngx-utils-lite';
|
|
102
|
-
|
|
103
|
-
@Injectable({ providedIn: 'root' })
|
|
104
|
-
export class MyService {
|
|
105
|
-
constructor(private num: NgxNumberUtils) { }
|
|
106
|
-
|
|
107
|
-
myMethod(): void {
|
|
108
|
-
this.num.formatCurrency(1234.56); // '$1,234.56'
|
|
109
|
-
this.num.formatBytes(1048576); // '1 MB'
|
|
110
|
-
this.num.formatPercent(0.756); // '75.6%'
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### Validation Utils
|
|
116
|
-
|
|
117
|
-
```typescript
|
|
118
|
-
import { Injectable } from '@angular/core';
|
|
119
|
-
import { NgxValidationUtils } from 'ngx-utils-lite';
|
|
120
|
-
|
|
121
|
-
@Injectable({ providedIn: 'root' })
|
|
122
|
-
export class MyService {
|
|
123
|
-
constructor(private val: NgxValidationUtils) { }
|
|
124
|
-
|
|
125
|
-
myMethod(): void {
|
|
126
|
-
this.val.isEmail('test@example.com'); // true
|
|
127
|
-
this.val.isUrl('https://google.com'); // true
|
|
128
|
-
this.val.isStrongPassword('Test123!'); // {valid: true, score: 4}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### ID Utils
|
|
134
|
-
|
|
135
|
-
```typescript
|
|
136
|
-
import { Injectable } from '@angular/core';
|
|
137
|
-
import { NgxIdUtils } from 'ngx-utils-lite';
|
|
138
|
-
|
|
139
|
-
@Injectable({ providedIn: 'root' })
|
|
140
|
-
export class MyService {
|
|
141
|
-
constructor(private id: NgxIdUtils) { }
|
|
142
|
-
|
|
143
|
-
myMethod(): void {
|
|
144
|
-
this.id.uuid(); // '550e8400-e29b-41d4-a716-446655440000'
|
|
145
|
-
this.id.nanoid(); // 'V1StGXR8_Z'
|
|
146
|
-
this.id.generateCode(6, 'numeric'); // '482931'
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
### Cookie Utils
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
import { Injectable } from '@angular/core';
|
|
155
|
-
import { NgxCookieUtils } from 'ngx-utils-lite';
|
|
156
|
-
|
|
157
|
-
@Injectable({ providedIn: 'root' })
|
|
158
|
-
export class MyService {
|
|
159
|
-
constructor(private cookie: NgxCookieUtils) { }
|
|
160
|
-
|
|
161
|
-
myMethod(): void {
|
|
162
|
-
this.cookie.set('theme', 'dark', 7); // Set cookie for 7 days
|
|
163
|
-
const theme = this.cookie.get('theme'); // Get cookie
|
|
164
|
-
const has = this.cookie.has('theme'); // Check if exists
|
|
165
|
-
this.cookie.delete('theme'); // Delete cookie
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### Copy to Clipboard Directive
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
import { Component } from '@angular/core';
|
|
174
|
-
import { NgxCopyToClipboardDirective } from 'ngx-utils-lite';
|
|
175
|
-
|
|
176
|
-
@Component({
|
|
177
|
-
selector: 'app-my-component',
|
|
178
|
-
standalone: true,
|
|
179
|
-
imports: [NgxCopyToClipboardDirective],
|
|
180
|
-
template: `
|
|
181
|
-
<input [(ngModel)]="text" placeholder="Enter text" />
|
|
182
|
-
<button [ngxCopyToClipboard]="text">Copy</button>
|
|
183
|
-
`
|
|
184
|
-
})
|
|
185
|
-
export class MyComponent {
|
|
186
|
-
text = 'Hello World';
|
|
187
|
-
}
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
## Demo
|
|
191
|
-
|
|
192
|
-
Visit the [demo page](http://localhost:4200/showcase) to see all utilities in action.
|
|
193
|
-
|
|
194
|
-
## Compatibility
|
|
195
|
-
|
|
196
|
-
- Angular 14+
|
|
197
|
-
- Standalone components
|
|
198
|
-
|
|
199
|
-
## License
|
|
200
|
-
|
|
201
|
-
MIT
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './object';
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './object';
|
package/dist/object.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare class ObjectUtils {
|
|
2
|
-
deepGet(obj: unknown, path: string, defaultValue?: unknown): unknown;
|
|
3
|
-
deepSet(obj: Record<string, unknown>, path: string, value: unknown): void;
|
|
4
|
-
deepClone<T>(obj: T): T;
|
|
5
|
-
merge<T extends Record<string, unknown>>(target: T, ...sources: (Partial<T> | undefined | null)[]): T;
|
|
6
|
-
omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Partial<T>;
|
|
7
|
-
pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Partial<T>;
|
|
8
|
-
isEmpty(value: unknown): boolean;
|
|
9
|
-
isEqual(a: unknown, b: unknown): boolean;
|
|
10
|
-
keys(obj: Record<string, unknown>): string[];
|
|
11
|
-
values(obj: Record<string, unknown>): unknown[];
|
|
12
|
-
entries(obj: Record<string, unknown>): [string, unknown][];
|
|
13
|
-
has(obj: Record<string, unknown>, path: string): boolean;
|
|
14
|
-
size(obj: Record<string, unknown>): number;
|
|
15
|
-
mapValues(obj: Record<string, unknown>, fn: (v: unknown, k: string) => unknown): Record<string, unknown>;
|
|
16
|
-
invert(obj: Record<string, string>): Record<string, string>;
|
|
17
|
-
clone<T>(obj: T): T;
|
|
18
|
-
}
|
package/dist/object.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
export class ObjectUtils {
|
|
2
|
-
deepGet(obj, path, defaultValue) {
|
|
3
|
-
if (!obj || !path)
|
|
4
|
-
return defaultValue;
|
|
5
|
-
const keys = path.split('.');
|
|
6
|
-
let result = obj;
|
|
7
|
-
for (const key of keys) {
|
|
8
|
-
if (result === null || result === undefined)
|
|
9
|
-
return defaultValue;
|
|
10
|
-
result = result[key];
|
|
11
|
-
}
|
|
12
|
-
return result ?? defaultValue;
|
|
13
|
-
}
|
|
14
|
-
deepSet(obj, path, value) {
|
|
15
|
-
const keys = path.split('.');
|
|
16
|
-
let current = obj;
|
|
17
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
18
|
-
if (!(keys[i] in current) || current[keys[i]] === null)
|
|
19
|
-
current[keys[i]] = {};
|
|
20
|
-
current = current[keys[i]];
|
|
21
|
-
}
|
|
22
|
-
current[keys[keys.length - 1]] = value;
|
|
23
|
-
}
|
|
24
|
-
deepClone(obj) {
|
|
25
|
-
if (obj === null || typeof obj !== 'object')
|
|
26
|
-
return obj;
|
|
27
|
-
if (obj instanceof Date)
|
|
28
|
-
return new Date(obj.getTime());
|
|
29
|
-
if (Array.isArray(obj))
|
|
30
|
-
return obj.map(item => this.deepClone(item));
|
|
31
|
-
const cloned = {};
|
|
32
|
-
for (const key in obj)
|
|
33
|
-
cloned[key] = this.deepClone(obj[key]);
|
|
34
|
-
return cloned;
|
|
35
|
-
}
|
|
36
|
-
merge(target, ...sources) {
|
|
37
|
-
for (const source of sources) {
|
|
38
|
-
if (!source)
|
|
39
|
-
continue;
|
|
40
|
-
for (const key of Object.keys(source)) {
|
|
41
|
-
const tv = target[key], sv = source[key];
|
|
42
|
-
if (tv && typeof tv === 'object' && sv && typeof sv === 'object' && !Array.isArray(tv) && !Array.isArray(sv)) {
|
|
43
|
-
target[key] = this.merge(tv, sv);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
target[key] = sv;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return target;
|
|
51
|
-
}
|
|
52
|
-
omit(obj, keys) {
|
|
53
|
-
const result = { ...obj };
|
|
54
|
-
keys.forEach(k => delete result[k]);
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
pick(obj, keys) {
|
|
58
|
-
const result = {};
|
|
59
|
-
keys.forEach(k => { if (k in obj)
|
|
60
|
-
result[k] = obj[k]; });
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
isEmpty(value) {
|
|
64
|
-
if (value === null || value === undefined)
|
|
65
|
-
return true;
|
|
66
|
-
if (typeof value === 'string')
|
|
67
|
-
return value.trim().length === 0;
|
|
68
|
-
if (Array.isArray(value))
|
|
69
|
-
return value.length === 0;
|
|
70
|
-
if (typeof value === 'object')
|
|
71
|
-
return Object.keys(value).length === 0;
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
isEqual(a, b) {
|
|
75
|
-
if (a === b)
|
|
76
|
-
return true;
|
|
77
|
-
if (!a || !b || typeof a !== 'object' || typeof b !== 'object')
|
|
78
|
-
return false;
|
|
79
|
-
const ak = Object.keys(a), bk = Object.keys(b);
|
|
80
|
-
return ak.length === bk.length && ak.every(k => this.isEqual(a[k], b[k]));
|
|
81
|
-
}
|
|
82
|
-
keys(obj) { return Object.keys(obj); }
|
|
83
|
-
values(obj) { return Object.values(obj); }
|
|
84
|
-
entries(obj) { return Object.entries(obj); }
|
|
85
|
-
has(obj, path) { return this.deepGet(obj, path) !== undefined; }
|
|
86
|
-
size(obj) { return Object.keys(obj).length; }
|
|
87
|
-
mapValues(obj, fn) {
|
|
88
|
-
const result = {};
|
|
89
|
-
for (const k of Object.keys(obj))
|
|
90
|
-
result[k] = fn(obj[k], k);
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
invert(obj) {
|
|
94
|
-
const result = {};
|
|
95
|
-
for (const k of Object.keys(obj))
|
|
96
|
-
result[obj[k]] = k;
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
clone(obj) { return this.deepClone(obj); }
|
|
100
|
-
}
|