ts-utils-lite is a lightweight, type-safe utility library designed for web developers, offering a comprehensive suite of helper functions across various domains. Currently stable at version 2.0.31, the library provides utilities for string manipulation, date formatting and calculations, array operations, object handling (including deep cloning and access), number formatting, robust validation, unique ID generation, cookie management, and both local and session storage interactions. It emphasizes modularity, allowing developers to either import the entire bundle or cherry-pick specific sub-packages (e.g., `ts-string-lite`, `ts-date-lite`) to optimize bundle size. The library is built with TypeScript, ensuring strong type inference and safety, making it an ideal companion for modern JavaScript and TypeScript projects, especially within frameworks like Angular, where its classes can be easily injected.
npm install ts-utils-liteVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `ts-utils-lite` within an Angular service, showcasing the instantiation and usage of various utility classes like StringUtils, DateUtils, ArrayUtils, ObjectUtils, ValidationUtils, and others, including environment-dependent Cookie and Storage utilities.
Ensure you instantiate the utility class before calling its methods, or use dependency injection if applicable (e.g., `private str: StringUtils`).
Use `import { StringUtils } from 'ts-string-lite';` for the dedicated string utilities package, and `import { StringUtils } from 'ts-utils-lite';` for the aggregated bundle.Wrap usage of `CookieUtils` and `StorageUtils` with checks for `typeof document !== 'undefined'` or `typeof localStorage !== 'undefined'` to ensure they only execute in browser contexts.
Prefer ES Module imports (`import { ... } from '...'`). If using CommonJS, ensure your build setup (e.g., Webpack, Rollup) or Node.js environment is configured to correctly handle ESM modules. You might need to adjust `tsconfig.json` (`"module": "Node16"` or `"ESNext"`) and `package.json` (`"type": "module"`).Ensure you are using `new StringUtils()` or injecting the class correctly. If using CommonJS, confirm the import: `const { StringUtils } = require('ts-utils-lite'); const str = new StringUtils();`.Install the specific sub-package: `npm install ts-string-lite` or ensure you are importing from the main `ts-utils-lite` package if you installed that: `import { StringUtils } from 'ts-utils-lite';`.Create an instance of `StringUtils` first, then call the method on the instance: `const strUtils = new StringUtils(); strUtils.slugify('...');`No dependency data recorded yet.