JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 152
  • Score
    100M100P100Q84215F
  • License MIT

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. Designed for flexibility, it works seamlessly across web, Node.js, React Native (including Expo), and server-side frameworks like NestJS, offering type safety, extensibility, and performance optimizations without platform-specific dependencies.

Package Exports

  • reslib/auth
  • reslib/build/auth/index.d.ts
  • reslib/build/auth/index.js
  • reslib/build/auth/types.d.ts
  • reslib/build/auth/types.js
  • reslib/build/countries/countries.d.ts
  • reslib/build/countries/countries.js
  • reslib/build/countries/index.d.ts
  • reslib/build/countries/index.js
  • reslib/build/countries/types.d.ts
  • reslib/build/countries/types.js
  • reslib/build/currency/currencies.d.ts
  • reslib/build/currency/currencies.js
  • reslib/build/currency/index.d.ts
  • reslib/build/currency/index.js
  • reslib/build/currency/session.d.ts
  • reslib/build/currency/session.js
  • reslib/build/currency/types.d.ts
  • reslib/build/currency/types.js
  • reslib/build/currency/utils.d.ts
  • reslib/build/currency/utils.js
  • reslib/build/exception/index.d.ts
  • reslib/build/exception/index.js
  • reslib/build/i18n/index.d.ts
  • reslib/build/i18n/index.js
  • reslib/build/i18n/types.d.ts
  • reslib/build/i18n/types.js
  • reslib/build/inputFormatter/index.d.ts
  • reslib/build/inputFormatter/index.js
  • reslib/build/inputFormatter/types.d.ts
  • reslib/build/inputFormatter/types.js
  • reslib/build/logger/index.d.ts
  • reslib/build/logger/index.js
  • reslib/build/observable/index.d.ts
  • reslib/build/observable/index.js
  • reslib/build/platform/index.d.ts
  • reslib/build/platform/index.js
  • reslib/build/resources/ResourcePaginationHelper.d.ts
  • reslib/build/resources/ResourcePaginationHelper.js
  • reslib/build/resources/decorators/create.decorator.d.ts
  • reslib/build/resources/decorators/create.decorator.js
  • reslib/build/resources/decorators/index.d.ts
  • reslib/build/resources/decorators/index.js
  • reslib/build/resources/fields/index.d.ts
  • reslib/build/resources/fields/index.js
  • reslib/build/resources/filters.d.ts
  • reslib/build/resources/filters.js
  • reslib/build/resources/index.d.ts
  • reslib/build/resources/index.js
  • reslib/build/resources/types/filters.d.ts
  • reslib/build/resources/types/filters.js
  • reslib/build/resources/types/index.d.ts
  • reslib/build/resources/types/index.js
  • reslib/build/session/index.d.ts
  • reslib/build/session/index.js
  • reslib/build/translations/auth.en.d.ts
  • reslib/build/translations/auth.en.js
  • reslib/build/translations/countries.en.d.ts
  • reslib/build/translations/countries.en.js
  • reslib/build/translations/currencies.en.d.ts
  • reslib/build/translations/currencies.en.js
  • reslib/build/translations/date.en.d.ts
  • reslib/build/translations/date.en.js
  • reslib/build/translations/index.d.ts
  • reslib/build/translations/index.js
  • reslib/build/translations/resources.en.d.ts
  • reslib/build/translations/resources.en.js
  • reslib/build/translations/validator.en.d.ts
  • reslib/build/translations/validator.en.js
  • reslib/build/types/date.d.ts
  • reslib/build/types/date.js
  • reslib/build/types/dictionary.d.ts
  • reslib/build/types/dictionary.js
  • reslib/build/types/index.d.ts
  • reslib/build/types/index.js
  • reslib/build/utils/areEquals.d.ts
  • reslib/build/utils/areEquals.js
  • reslib/build/utils/date/dateHelper.d.ts
  • reslib/build/utils/date/dateHelper.js
  • reslib/build/utils/date/index.d.ts
  • reslib/build/utils/date/index.js
  • reslib/build/utils/date/isDateObj.d.ts
  • reslib/build/utils/date/isDateObj.js
  • reslib/build/utils/debounce.d.ts
  • reslib/build/utils/debounce.js
  • reslib/build/utils/defaultArray.d.ts
  • reslib/build/utils/defaultArray.js
  • reslib/build/utils/defaultBool.d.ts
  • reslib/build/utils/defaultBool.js
  • reslib/build/utils/defaultStr.d.ts
  • reslib/build/utils/defaultStr.js
  • reslib/build/utils/defaultVal.d.ts
  • reslib/build/utils/defaultVal.js
  • reslib/build/utils/dom/index.d.ts
  • reslib/build/utils/dom/index.js
  • reslib/build/utils/dom/isDOMElement.d.ts
  • reslib/build/utils/dom/isDOMElement.js
  • reslib/build/utils/file/index.d.ts
  • reslib/build/utils/file/index.js
  • reslib/build/utils/global.d.ts
  • reslib/build/utils/global.js
  • reslib/build/utils/image.d.ts
  • reslib/build/utils/image.js
  • reslib/build/utils/index.d.ts
  • reslib/build/utils/index.js
  • reslib/build/utils/interpolate.d.ts
  • reslib/build/utils/interpolate.js
  • reslib/build/utils/isEmail.d.ts
  • reslib/build/utils/isEmail.js
  • reslib/build/utils/isEmpty.d.ts
  • reslib/build/utils/isEmpty.js
  • reslib/build/utils/isHexadecimal.d.ts
  • reslib/build/utils/isHexadecimal.js
  • reslib/build/utils/isMongoId.d.ts
  • reslib/build/utils/isMongoId.js
  • reslib/build/utils/isNonNullString.d.ts
  • reslib/build/utils/isNonNullString.js
  • reslib/build/utils/isNullable.d.ts
  • reslib/build/utils/isNullable.js
  • reslib/build/utils/isNumber.d.ts
  • reslib/build/utils/isNumber.js
  • reslib/build/utils/isPrimitive.d.ts
  • reslib/build/utils/isPrimitive.js
  • reslib/build/utils/isPromise.d.ts
  • reslib/build/utils/isPromise.js
  • reslib/build/utils/isRegex.d.ts
  • reslib/build/utils/isRegex.js
  • reslib/build/utils/isTime.d.ts
  • reslib/build/utils/isTime.js
  • reslib/build/utils/json.d.ts
  • reslib/build/utils/json.js
  • reslib/build/utils/numbers.d.ts
  • reslib/build/utils/numbers.js
  • reslib/build/utils/object.d.ts
  • reslib/build/utils/object.js
  • reslib/build/utils/sort.d.ts
  • reslib/build/utils/sort.js
  • reslib/build/utils/string.d.ts
  • reslib/build/utils/string.js
  • reslib/build/utils/stringify.d.ts
  • reslib/build/utils/stringify.js
  • reslib/build/utils/uniqid.d.ts
  • reslib/build/utils/uniqid.js
  • reslib/build/utils/uri/index.d.ts
  • reslib/build/utils/uri/index.js
  • reslib/build/validator/errors/index.d.ts
  • reslib/build/validator/errors/index.js
  • reslib/build/validator/index.d.ts
  • reslib/build/validator/index.js
  • reslib/build/validator/rules.types.d.ts
  • reslib/build/validator/rules.types.js
  • reslib/build/validator/rules/array.d.ts
  • reslib/build/validator/rules/array.js
  • reslib/build/validator/rules/boolean.d.ts
  • reslib/build/validator/rules/boolean.js
  • reslib/build/validator/rules/date.d.ts
  • reslib/build/validator/rules/date.js
  • reslib/build/validator/rules/default.d.ts
  • reslib/build/validator/rules/default.js
  • reslib/build/validator/rules/enum.d.ts
  • reslib/build/validator/rules/enum.js
  • reslib/build/validator/rules/file.d.ts
  • reslib/build/validator/rules/file.js
  • reslib/build/validator/rules/format.d.ts
  • reslib/build/validator/rules/format.js
  • reslib/build/validator/rules/index.d.ts
  • reslib/build/validator/rules/index.js
  • reslib/build/validator/rules/multiRules.d.ts
  • reslib/build/validator/rules/multiRules.js
  • reslib/build/validator/rules/numeric.d.ts
  • reslib/build/validator/rules/numeric.js
  • reslib/build/validator/rules/object.d.ts
  • reslib/build/validator/rules/object.js
  • reslib/build/validator/rules/string.d.ts
  • reslib/build/validator/rules/string.js
  • reslib/build/validator/rules/target.d.ts
  • reslib/build/validator/rules/target.js
  • reslib/build/validator/rules/utils.d.ts
  • reslib/build/validator/rules/utils.js
  • reslib/build/validator/rulesMarkers.d.ts
  • reslib/build/validator/rulesMarkers.js
  • reslib/build/validator/types.d.ts
  • reslib/build/validator/types.js
  • reslib/build/validator/validator.d.ts
  • reslib/build/validator/validator.js
  • reslib/countries
  • reslib/currency
  • reslib/exception
  • reslib/i18n
  • reslib/inputFormatter
  • reslib/logger
  • reslib/observable
  • reslib/platform
  • reslib/resources
  • reslib/session
  • reslib/types
  • reslib/utils
  • reslib/validator

Readme

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. 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.

Table of Contents

πŸš€ Key Features

  • Decorator-Driven Resource Management: Use decorators to intuitively define and manage resources, resulting in cleaner, more expressive code.
  • Modular Architecture: Treat every component as a resource, promoting reusability and better organization of application logic.
  • Extensible Framework: Effortlessly extend core functionalities by adding custom field types, decorators, and plugins tailored to specific project needs.
  • 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.
  • Type Safety: Developed with TypeScript, ensuring robust type-checking for a reliable foundation for scalable applications.
  • Intuitive API: Enjoy a developer-friendly API that leverages TypeScript features for smooth auto-completion and type hints.
  • Dynamic Ecosystem: Easily adapt to evolving project requirements by integrating external decorators and features, allowing for a responsive and flexible development environment.
  • Production Ready: Optimized for performance, with comprehensive testing, documentation, and support for major platforms.

🌐 Supported Platforms

  • Web: Full browser support with modern bundlers
  • React Native: Seamless integration with Expo and bare React Native
  • NestJS: Server-side framework support for backend applications
  • Node.js: Server-side JavaScript runtime compatibility

βš™οΈ Getting Started

To begin using ResLib, follow these steps:

1. Prerequisites

Make sure you have the following installed on your machine:

  • Node.js (version 16 or higher)
  • npm (Node Package Manager)

2. πŸ› οΈΒ Install Required Packages

To set up ResLib, run the following command:

npm install reslib reflect-metadata
# or
yarn add reslib reflect-metadata

For Expo/React Native projects:

npx expo install reslib reflect-metadata

For NestJS projects:

npm install reslib reflect-metadata @nestjs/common

Also, install the necessary TypeScript dev dependencies:

npm install --save-dev typescript @types/node # or yarn add -D typescript @types/node

3. TypeScript Configuration

Create a tsconfig.json file in your project root with the following configuration:

Create a tsconfig.json file in your project root with the following configuration:

{
    "compilerOptions": {
      "esModuleInterop": true,
      "forceConsistentCasingInFileNames": true,
      "target": "es6",                          // Use ES6 or higher
      "module": "commonjs",                     // Use commonjs module system
      "experimentalDecorators": true,           // Enable experimental support for decorators
      "emitDecoratorMetadata": true,             // Enable emitting design:type metadata
      "strict": true,                            // Enable all strict type checking options
      "skipLibCheck": true                       // Skip type checking of declaration files
    },
    "include": ["src/**/*"],
    "exclude": ["node_modules"]
}

4. Import reflect-metadata

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.

import 'reflect-metadata';

πŸ“š Documentation

Resources

  • Resources are the foundation of ResLib. Use the @ResourceMeta decorator to define any logical entity (models, components, etc.).

  • Fields: Add fields to your resources using the @FieldMeta decorator, specifying field types and options.

  • symbol : Simple symbol field;

  • switch : Can be a number of a boolean;

  • checkbox: Can be a number of a boolean;

Validation

Powerful validation system with 70+ rules, decorators, functional schemas, and batch processing.

  • Decorator-based: @IsRequired(), @IsEmail(), etc.
  • Object-based (Zod-like): Validator.object({ email: ['Required', 'Email'] }).
  • Batch validation: Validator.validateBulk(User, data).
  • Async & i18n support.

Once you have installed the necessary packages and set up TypeScript, you can start defining resources and fields using ResLib decorators.

Basic Example

import 'reflect-metadata';
import { ResourceMeta, FieldMeta } from 'reslib';

@ResourceMeta()
class User {
  @FieldMeta({ type: 'string' })
  name: string;

  @FieldMeta({ type: 'number' })
  age: number;

  @FieldMeta({ type: 'email' })
  email: string;
}

Examples

Defining Custom FieldMeta Types

@FieldMeta({ type: 'dropdown', options: ['Admin', 'User', 'Guest'] })
role: string;

@FieldMeta({ type: 'selectResource', resourceName: 'Product' })
favoriteProduct: string;

Creating Extensible Decorators

You can easily create and register new decorators to extend the functionality of your resources.

function CustomField(options: { customProp: string }) {
  return function (target: any, propertyKey: string) {
    // Custom decorator logic
    Reflect.defineMetadata(
      'customProp',
      options.customProp,
      target,
      propertyKey
    );
  };
}

Advanced Examples

πŸ”„ Extending the Framework

ResLib is designed for flexibility. You can add your own custom field types or extend existing ones with full TypeScript support.

Extending FieldMeta Types

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.

function ExtendedField(type: string, options: any) {
    return function (target: any, propertyKey: string) {
        Reflect.defineMetadata('design:type', type, target, propertyKey);
        Reflect.defineMetadata('field:options', options, target, propertyKey);
    };
}

// Define a new field type for a color picker
@ExtendedField('colorPicker', { defaultColor: '#000000' })
color: string;

This allows ResLib to recognize new custom field types, complete with IntelliSense support.

Adding New Resources

You can create new resources and leverage the existing decorators for rich resource definitions.

@ResourceMeta()
class Product {
  @FieldMeta({ type: 'string' })
  productName: string;

  @FieldMeta({ type: 'number' })
  price: number;

  @FieldMeta({
    type: 'string',
    options: { enum: ['In Stock', 'Out of Stock'] },
  })
  availability: string;
}

Custom Decorator for Advanced Logic

You can also create custom decorators that implement advanced logic, such as validation or transformation.

function IsPositive(target: any, propertyKey: string) {
    const value = target[propertyKey];
    if (value < 0) {
        throw new Error(`${propertyKey} must be a positive number.`);
    }
}

@ResourceMeta()
class Order {
    @FieldMeta({ type: 'number' })
    @IsPositive
    totalAmount: number;

    @FieldMeta({ type: 'string' })
    customerName: string;
}

Using Extended FieldMeta Types

Here’s how you can use the newly defined field types in a resource:

@ResourceMeta()
class EnhancedUser {
  @FieldMeta({ type: 'string' })
  name: string;

  @ExtendedField('colorPicker', { defaultColor: '#FF0000' })
  favoriteColor: string;
}

πŸ”Œ Plugins & Extensions

ResLib can be extended with plugins and custom modules. Define new decorators, extend resource behavior, and add complex validation logic as needed.

Example: Custom Decorator Plugin

import { ResourceMeta, FieldMeta, customDecorator } from 'reslib';

function LogField() {
  return customDecorator((target, key) => {
    console.log(`FieldMeta '${key}' has been initialized.`);
  });
}

@ResourceMeta
class Product {
  @LogField()
  @FieldMeta({ type: "number" })
  price: number;
}

🧩 Contributing

We welcome contributions! Please see our Contributing Guide for details on how to get started.

πŸ“œ License

ResLib is licensed under the MIT License.

πŸ›  Built With

  • TypeScript: Type-safe, scalable development.
  • Reflect-metadata: For decorator metadata reflection.
  • Custom Decorators: A clean and declarative way to extend functionality.

πŸ‘ Acknowledgements

Thanks to the open-source community for contributions and inspiration.

πŸ“¬ Contact

For support or inquiries: