reslib 1.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.
Files changed (200) hide show
  1. package/README.md +298 -0
  2. package/build/auth/index.d.ts +2034 -0
  3. package/build/auth/index.js +5 -0
  4. package/build/auth/types.d.ts +465 -0
  5. package/build/auth/types.js +1 -0
  6. package/build/countries/countries.d.ts +1454 -0
  7. package/build/countries/countries.js +1 -0
  8. package/build/countries/index.d.ts +159 -0
  9. package/build/countries/index.js +5 -0
  10. package/build/countries/types.d.ts +65 -0
  11. package/build/countries/types.js +1 -0
  12. package/build/currency/currencies.d.ts +8 -0
  13. package/build/currency/currencies.js +1 -0
  14. package/build/currency/index.d.ts +51 -0
  15. package/build/currency/index.js +5 -0
  16. package/build/currency/session.d.ts +23 -0
  17. package/build/currency/session.js +5 -0
  18. package/build/currency/types.d.ts +1039 -0
  19. package/build/currency/types.js +1 -0
  20. package/build/currency/utils.d.ts +25 -0
  21. package/build/currency/utils.js +1 -0
  22. package/build/i18n/index.d.ts +640 -0
  23. package/build/i18n/index.js +5 -0
  24. package/build/inputFormatter/index.d.ts +396 -0
  25. package/build/inputFormatter/index.js +5 -0
  26. package/build/inputFormatter/types.d.ts +544 -0
  27. package/build/inputFormatter/types.js +1 -0
  28. package/build/logger/index.d.ts +235 -0
  29. package/build/logger/index.js +5 -0
  30. package/build/observable/index.d.ts +329 -0
  31. package/build/observable/index.js +1 -0
  32. package/build/platform/index.d.ts +32 -0
  33. package/build/platform/index.js +1 -0
  34. package/build/resources/ResourcePaginationHelper.d.ts +537 -0
  35. package/build/resources/ResourcePaginationHelper.js +2 -0
  36. package/build/resources/decorators/create.decorator.d.ts +20 -0
  37. package/build/resources/decorators/create.decorator.js +1 -0
  38. package/build/resources/decorators/index.d.ts +41 -0
  39. package/build/resources/decorators/index.js +1 -0
  40. package/build/resources/fields/index.d.ts +33 -0
  41. package/build/resources/fields/index.js +1 -0
  42. package/build/resources/filters.d.ts +62 -0
  43. package/build/resources/filters.js +1 -0
  44. package/build/resources/index.d.ts +854 -0
  45. package/build/resources/index.js +6 -0
  46. package/build/resources/types/filters.d.ts +508 -0
  47. package/build/resources/types/filters.js +1 -0
  48. package/build/resources/types/index.d.ts +4138 -0
  49. package/build/resources/types/index.js +1 -0
  50. package/build/session/index.d.ts +1474 -0
  51. package/build/session/index.js +1 -0
  52. package/build/translations/auth.en.d.ts +3 -0
  53. package/build/translations/auth.en.js +1 -0
  54. package/build/translations/countries.en.d.ts +6 -0
  55. package/build/translations/countries.en.js +1 -0
  56. package/build/translations/currencies.en.d.ts +5 -0
  57. package/build/translations/currencies.en.js +1 -0
  58. package/build/translations/date.en.d.ts +19 -0
  59. package/build/translations/date.en.js +1 -0
  60. package/build/translations/index.d.ts +1583 -0
  61. package/build/translations/index.js +5 -0
  62. package/build/translations/resources.en.d.ts +6 -0
  63. package/build/translations/resources.en.js +1 -0
  64. package/build/translations/validator.en.d.ts +104 -0
  65. package/build/translations/validator.en.js +5 -0
  66. package/build/types/date.d.ts +44 -0
  67. package/build/types/date.js +1 -0
  68. package/build/types/dictionary.d.ts +29 -0
  69. package/build/types/dictionary.js +1 -0
  70. package/build/types/i18n.d.ts +121 -0
  71. package/build/types/i18n.js +1 -0
  72. package/build/types/index.d.ts +145 -0
  73. package/build/types/index.js +1 -0
  74. package/build/utils/areEquals.d.ts +19 -0
  75. package/build/utils/areEquals.js +1 -0
  76. package/build/utils/date/dateHelper.d.ts +371 -0
  77. package/build/utils/date/dateHelper.js +5 -0
  78. package/build/utils/date/index.d.ts +212 -0
  79. package/build/utils/date/index.js +5 -0
  80. package/build/utils/date/isDateObj.d.ts +14 -0
  81. package/build/utils/date/isDateObj.js +1 -0
  82. package/build/utils/debounce.d.ts +52 -0
  83. package/build/utils/debounce.js +1 -0
  84. package/build/utils/defaultArray.d.ts +18 -0
  85. package/build/utils/defaultArray.js +1 -0
  86. package/build/utils/defaultBool.d.ts +14 -0
  87. package/build/utils/defaultBool.js +1 -0
  88. package/build/utils/defaultStr.d.ts +17 -0
  89. package/build/utils/defaultStr.js +1 -0
  90. package/build/utils/defaultVal.d.ts +18 -0
  91. package/build/utils/defaultVal.js +1 -0
  92. package/build/utils/dom/index.d.ts +65 -0
  93. package/build/utils/dom/index.js +1 -0
  94. package/build/utils/dom/isDOMElement.d.ts +11 -0
  95. package/build/utils/dom/isDOMElement.js +1 -0
  96. package/build/utils/file/index.d.ts +26 -0
  97. package/build/utils/file/index.js +1 -0
  98. package/build/utils/global.d.ts +53 -0
  99. package/build/utils/global.js +1 -0
  100. package/build/utils/image.d.ts +56 -0
  101. package/build/utils/image.js +1 -0
  102. package/build/utils/index.d.ts +39 -0
  103. package/build/utils/index.js +6 -0
  104. package/build/utils/interpolate.d.ts +105 -0
  105. package/build/utils/interpolate.js +1 -0
  106. package/build/utils/isEmail.d.ts +57 -0
  107. package/build/utils/isEmail.js +1 -0
  108. package/build/utils/isEmpty.d.ts +18 -0
  109. package/build/utils/isEmpty.js +1 -0
  110. package/build/utils/isNonNullString.d.ts +17 -0
  111. package/build/utils/isNonNullString.js +1 -0
  112. package/build/utils/isNullable.d.ts +7 -0
  113. package/build/utils/isNullable.js +1 -0
  114. package/build/utils/isNumber.d.ts +36 -0
  115. package/build/utils/isNumber.js +1 -0
  116. package/build/utils/isPrimitive.d.ts +16 -0
  117. package/build/utils/isPrimitive.js +1 -0
  118. package/build/utils/isPromise.d.ts +14 -0
  119. package/build/utils/isPromise.js +1 -0
  120. package/build/utils/isRegex.d.ts +15 -0
  121. package/build/utils/isRegex.js +1 -0
  122. package/build/utils/isTime.d.ts +18 -0
  123. package/build/utils/isTime.js +1 -0
  124. package/build/utils/json.d.ts +224 -0
  125. package/build/utils/json.js +1 -0
  126. package/build/utils/numbers.d.ts +148 -0
  127. package/build/utils/numbers.js +5 -0
  128. package/build/utils/object.d.ts +567 -0
  129. package/build/utils/object.js +1 -0
  130. package/build/utils/sort.d.ts +67 -0
  131. package/build/utils/sort.js +1 -0
  132. package/build/utils/string.d.ts +165 -0
  133. package/build/utils/string.js +1 -0
  134. package/build/utils/stringify.d.ts +23 -0
  135. package/build/utils/stringify.js +1 -0
  136. package/build/utils/uniqid.d.ts +18 -0
  137. package/build/utils/uniqid.js +1 -0
  138. package/build/utils/uri/index.d.ts +333 -0
  139. package/build/utils/uri/index.js +2 -0
  140. package/build/validator/index.d.ts +4 -0
  141. package/build/validator/index.js +6 -0
  142. package/build/validator/rules/array.d.ts +848 -0
  143. package/build/validator/rules/array.js +5 -0
  144. package/build/validator/rules/boolean.d.ts +87 -0
  145. package/build/validator/rules/boolean.js +5 -0
  146. package/build/validator/rules/date.d.ts +551 -0
  147. package/build/validator/rules/date.js +5 -0
  148. package/build/validator/rules/default.d.ts +367 -0
  149. package/build/validator/rules/default.js +5 -0
  150. package/build/validator/rules/enum.d.ts +155 -0
  151. package/build/validator/rules/enum.js +5 -0
  152. package/build/validator/rules/file.d.ts +356 -0
  153. package/build/validator/rules/file.js +5 -0
  154. package/build/validator/rules/format.d.ts +2825 -0
  155. package/build/validator/rules/format.js +6 -0
  156. package/build/validator/rules/index.d.ts +16 -0
  157. package/build/validator/rules/index.js +6 -0
  158. package/build/validator/rules/multiRules.d.ts +475 -0
  159. package/build/validator/rules/multiRules.js +5 -0
  160. package/build/validator/rules/numeric.d.ts +1135 -0
  161. package/build/validator/rules/numeric.js +5 -0
  162. package/build/validator/rules/string.d.ts +504 -0
  163. package/build/validator/rules/string.js +5 -0
  164. package/build/validator/rules/target.d.ts +137 -0
  165. package/build/validator/rules/target.js +5 -0
  166. package/build/validator/rules/utils.d.ts +1 -0
  167. package/build/validator/rules/utils.js +1 -0
  168. package/build/validator/rulesMarkers.d.ts +11 -0
  169. package/build/validator/rulesMarkers.js +1 -0
  170. package/build/validator/types.d.ts +2906 -0
  171. package/build/validator/types.js +1 -0
  172. package/build/validator/validator.d.ts +3692 -0
  173. package/build/validator/validator.js +5 -0
  174. package/lib/cjs/auth.js +1 -0
  175. package/lib/cjs/countries.js +1 -0
  176. package/lib/cjs/currency.js +1 -0
  177. package/lib/cjs/i18n.js +1 -0
  178. package/lib/cjs/inputFormatter.js +1 -0
  179. package/lib/cjs/logger.js +1 -0
  180. package/lib/cjs/observable.js +1 -0
  181. package/lib/cjs/platform.js +1 -0
  182. package/lib/cjs/resources.js +1 -0
  183. package/lib/cjs/session.js +1 -0
  184. package/lib/cjs/types.js +1 -0
  185. package/lib/cjs/utils.js +1 -0
  186. package/lib/cjs/validator.js +1 -0
  187. package/lib/esm/auth.mjs +1 -0
  188. package/lib/esm/countries.mjs +1 -0
  189. package/lib/esm/currency.mjs +1 -0
  190. package/lib/esm/i18n.mjs +1 -0
  191. package/lib/esm/inputFormatter.mjs +1 -0
  192. package/lib/esm/logger.mjs +1 -0
  193. package/lib/esm/observable.mjs +1 -0
  194. package/lib/esm/platform.mjs +1 -0
  195. package/lib/esm/resources.mjs +1 -0
  196. package/lib/esm/session.mjs +1 -0
  197. package/lib/esm/types.mjs +1 -0
  198. package/lib/esm/utils.mjs +1 -0
  199. package/lib/esm/validator.mjs +1 -0
  200. package/package.json +244 -0
package/README.md ADDED
@@ -0,0 +1,298 @@
1
+ **ResLib** is a lightweight, production-ready TypeScript library for decorator-based resource management and application utilities. ResLib provides a modular framework for building scalable applications with features like authentication, internationalization, validation, session management, and observable patterns.
2
+ It is fully cross-platformβ€”compatible with web, Node.js, React Native (including Expo), and server environments like NestJSβ€”while delivering strong type safety, high flexibility, and optimized performance without relying on platform-specific dependencies.
3
+
4
+ ## **Table of Contents**
5
+
6
+ - [Key Features](#key-features)
7
+ - [Supported Platforms](#supported-platforms)
8
+ - [Getting Started](#getting-started)
9
+ - [Usage](#usage)
10
+ - [Advanced Examples](#advanced-examples)
11
+ - [Contributing](#contributing)
12
+ - [License](#license)
13
+
14
+ ## πŸš€ Key **Features**
15
+
16
+ - **Decorator-Driven Resource Management**: Use decorators to intuitively define and manage resources, resulting in cleaner, more expressive code.
17
+ - **Modular Architecture**: Treat every component as a resource, promoting reusability and better organization of application logic.
18
+ - **Extensible Framework**: Effortlessly extend core functionalities by adding custom field types, decorators, and plugins tailored to specific project needs.
19
+ - **Customizable FieldMeta Types**: Support for various built-in field types (such as number, dropdown, selectResource) that can be customized with specific properties for flexible data handling.
20
+ - **Type Safety**: Developed with TypeScript, ensuring robust type-checking for a reliable foundation for scalable applications.
21
+ - **Intuitive API**: Enjoy a developer-friendly API that leverages TypeScript features for smooth auto-completion and type hints.
22
+ - **Dynamic Ecosystem**: Easily adapt to evolving project requirements by integrating external decorators and features, allowing for a responsive and flexible development environment.
23
+ - **Production Ready**: Optimized for performance, with comprehensive testing, documentation, and support for major platforms.
24
+
25
+ ## 🌐 Supported Platforms
26
+
27
+ - **Web**: Full browser support with modern bundlers
28
+ - **React Native**: Seamless integration with Expo and bare React Native
29
+ - **NestJS**: Server-side framework support for backend applications
30
+ - **Node.js**: Server-side JavaScript runtime compatibility
31
+
32
+ ## βš™οΈ **Getting Started**
33
+
34
+ To begin using **ResLib**, follow these steps:
35
+
36
+ ### **1\. Prerequisites**
37
+
38
+ Make sure you have the following installed on your machine:
39
+
40
+ - Node.js (version 16 or higher)
41
+ - npm (Node Package Manager)
42
+
43
+ ### **2\. πŸ› οΈΒ Install Required Packages**
44
+
45
+ To set up ResLib, run the following command:
46
+
47
+ ```typescript
48
+ npm install reslib reflect-metadata
49
+ # or
50
+ yarn add reslib reflect-metadata
51
+ ```
52
+
53
+ For Expo/React Native projects:
54
+
55
+ ```typescript
56
+ npx expo install reslib reflect-metadata
57
+ ```
58
+
59
+ For NestJS projects:
60
+
61
+ ```typescript
62
+ npm install reslib reflect-metadata @nestjs/common
63
+ ```
64
+
65
+ Also, install the necessary TypeScript dev dependencies:
66
+
67
+ ```plaintext
68
+ npm install --save-dev typescript @types/node # or yarn add -D typescript @types/node
69
+ ```
70
+
71
+ ### **3\. TypeScript Configuration**
72
+
73
+ Create a `tsconfig.json` file in your project root with the following configuration:
74
+
75
+ Create a `tsconfig.json` file in your project root with the following configuration:
76
+
77
+ ```typescript
78
+ {
79
+ "compilerOptions": {
80
+ "esModuleInterop": true,
81
+ "forceConsistentCasingInFileNames": true,
82
+ "target": "es6", // Use ES6 or higher
83
+ "module": "commonjs", // Use commonjs module system
84
+ "experimentalDecorators": true, // Enable experimental support for decorators
85
+ "emitDecoratorMetadata": true, // Enable emitting design:type metadata
86
+ "strict": true, // Enable all strict type checking options
87
+ "skipLibCheck": true // Skip type checking of declaration files
88
+ },
89
+ "include": ["src/**/*"],
90
+ "exclude": ["node_modules"]
91
+ }
92
+ ```
93
+
94
+ ### 4\. **Import** `reflect-metadata`
95
+
96
+ In your entry file (usually `index.ts` or `app.ts`), ensure that you import `reflect-metadata` at the very top of the file. This is required to enable metadata reflection for decorators.
97
+
98
+ ```typescript
99
+ import 'reflect-metadata';
100
+ ```
101
+
102
+ ## πŸ“š **Documentation**
103
+
104
+ ### Resources
105
+
106
+ - **Resources** are the foundation of ResLib. Use the `@ResourceMeta` decorator to define any logical entity (models, components, etc.).
107
+ - **Fields**: Add fields to your resources using the `@FieldMeta` decorator, specifying field types and options.
108
+
109
+ ### Built-In FieldMeta Types
110
+
111
+ - **number**: Simple number field.
112
+ - **string**: Simple string field;
113
+ - **boolean**: Simple boolean field;
114
+ - **symbol** : Simple symbol field;
115
+ - **switch** : Can be a number of a boolean;
116
+ - **checkbox**: Can be a number of a boolean;
117
+
118
+ Once you have installed the necessary packages and set up TypeScript, you can start defining resources and fields using ResLib decorators.
119
+
120
+ ### **Basic Example**
121
+
122
+ ```typescript
123
+ import 'reflect-metadata';
124
+ import { ResourceMeta, FieldMeta } from 'reslib';
125
+
126
+ @ResourceMeta()
127
+ class User {
128
+ @FieldMeta({ type: 'string' })
129
+ name: string;
130
+
131
+ @FieldMeta({ type: 'number' })
132
+ age: number;
133
+
134
+ @FieldMeta({ type: 'email' })
135
+ email: string;
136
+ }
137
+ ```
138
+
139
+ ## **Examples**
140
+
141
+ ### **Defining Custom FieldMeta Types**
142
+
143
+ ```typescript
144
+ @FieldMeta({ type: 'dropdown', options: ['Admin', 'User', 'Guest'] })
145
+ role: string;
146
+
147
+ @FieldMeta({ type: 'selectResource', resourceName: 'Product' })
148
+ favoriteProduct: string;
149
+ ```
150
+
151
+ ### **Creating Extensible Decorators**
152
+
153
+ You can easily create and register new decorators to extend the functionality of your resources.
154
+
155
+ ```typescript
156
+ function CustomField(options: { customProp: string }) {
157
+ return function (target: any, propertyKey: string) {
158
+ // Custom decorator logic
159
+ Reflect.defineMetadata(
160
+ 'customProp',
161
+ options.customProp,
162
+ target,
163
+ propertyKey
164
+ );
165
+ };
166
+ }
167
+ ```
168
+
169
+ ## **Advanced Examples**
170
+
171
+ ### πŸ”„ **Extending the Framework**
172
+
173
+ ResLib is designed for flexibility. You can add your own custom field types or extend existing ones with full TypeScript support.
174
+
175
+ ### **Extending FieldMeta Types**
176
+
177
+ You can easily extend the field types available in ResLib by creating custom decorators. To extend field types and register custom options (e.g., a `rating` field), use TypeScript's **declaration merging**.
178
+
179
+ ```typescript
180
+ function ExtendedField(type: string, options: any) {
181
+ return function (target: any, propertyKey: string) {
182
+ Reflect.defineMetadata('design:type', type, target, propertyKey);
183
+ Reflect.defineMetadata('field:options', options, target, propertyKey);
184
+ };
185
+ }
186
+
187
+ // Define a new field type for a color picker
188
+ @ExtendedField('colorPicker', { defaultColor: '#000000' })
189
+ color: string;
190
+ ```
191
+
192
+ ### This allows ResLib to recognize new custom field types, complete with IntelliSense support.
193
+
194
+ ### **Adding New Resources**
195
+
196
+ You can create new resources and leverage the existing decorators for rich resource definitions.
197
+
198
+ ```typescript
199
+ @ResourceMeta()
200
+ class Product {
201
+ @FieldMeta({ type: 'string' })
202
+ productName: string;
203
+
204
+ @FieldMeta({ type: 'number' })
205
+ price: number;
206
+
207
+ @FieldMeta({
208
+ type: 'string',
209
+ options: { enum: ['In Stock', 'Out of Stock'] },
210
+ })
211
+ availability: string;
212
+ }
213
+ ```
214
+
215
+ ### **Custom Decorator for Advanced Logic**
216
+
217
+ You can also create custom decorators that implement advanced logic, such as validation or transformation.
218
+
219
+ ```typescript
220
+ function IsPositive(target: any, propertyKey: string) {
221
+ const value = target[propertyKey];
222
+ if (value < 0) {
223
+ throw new Error(`${propertyKey} must be a positive number.`);
224
+ }
225
+ }
226
+
227
+ @ResourceMeta()
228
+ class Order {
229
+ @FieldMeta({ type: 'number' })
230
+ @IsPositive
231
+ totalAmount: number;
232
+
233
+ @FieldMeta({ type: 'string' })
234
+ customerName: string;
235
+ }
236
+ ```
237
+
238
+ ### **Using Extended FieldMeta Types**
239
+
240
+ Here’s how you can use the newly defined field types in a resource:
241
+
242
+ ```typescript
243
+ @ResourceMeta()
244
+ class EnhancedUser {
245
+ @FieldMeta({ type: 'string' })
246
+ name: string;
247
+
248
+ @ExtendedField('colorPicker', { defaultColor: '#FF0000' })
249
+ favoriteColor: string;
250
+ }
251
+ ```
252
+
253
+ ## πŸ”Œ **Plugins & Extensions**
254
+
255
+ ResLib can be extended with plugins and custom modules. Define new decorators, extend resource behavior, and add complex validation logic as needed.
256
+
257
+ ### Example: Custom Decorator Plugin
258
+
259
+ ```typescript
260
+ import { ResourceMeta, FieldMeta, customDecorator } from 'reslib';
261
+
262
+ function LogField() {
263
+ return customDecorator((target, key) => {
264
+ console.log(`FieldMeta '${key}' has been initialized.`);
265
+ });
266
+ }
267
+
268
+ @ResourceMeta
269
+ class Product {
270
+ @LogField()
271
+ @FieldMeta({ type: "number" })
272
+ price: number;
273
+ }
274
+ ```
275
+
276
+ ## 🧩 **Contributing**
277
+
278
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on how to get started.
279
+
280
+ ## πŸ“œ **License**
281
+
282
+ ResLib is licensed under the MIT License.
283
+
284
+ ## πŸ›  **Built With**
285
+
286
+ - **TypeScript**: Type-safe, scalable development.
287
+ - **Reflect-metadata**: For decorator metadata reflection.
288
+ - **Custom Decorators**: A clean and declarative way to extend functionality.
289
+
290
+ ## πŸ‘ **Acknowledgements**
291
+
292
+ Thanks to the open-source community for contributions and inspiration.
293
+
294
+ ## πŸ“¬ **Contact**
295
+
296
+ For support or inquiries:
297
+
298
+ - GitHub:Β  [GitHub Link](https://github.com/boris-fouomene/reslib)