ts-cookie-lite 0.0.2 → 0.0.3-beta.1
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 -0
- package/README.md +201 -0
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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
|