{"id":18073,"library":"ts-utils-lite","title":"TS Utils Lite","description":"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.","status":"active","version":"2.0.31","language":"javascript","source_language":"en","source_url":"https://github.com/gbmrocks/ts-utils-lite","tags":["javascript","angular","ngx","utility","helpers","typescript","es6","utils"],"install":[{"cmd":"npm install ts-utils-lite","lang":"bash","label":"npm"},{"cmd":"yarn add ts-utils-lite","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-utils-lite","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Main aggregate import. `StringUtils` is an instantiable class, not a static namespace.","wrong":"const StringUtils = require('ts-utils-lite').StringUtils;","symbol":"StringUtils","correct":"import { StringUtils } from 'ts-utils-lite';"},{"note":"All utility classes are named exports from the main `ts-utils-lite` package.","wrong":"import DateUtils from 'ts-utils-lite';","symbol":"DateUtils","correct":"import { DateUtils } from 'ts-utils-lite';"},{"note":"For individual sub-packages, import directly from their respective npm package names (e.g., `ts-validation-lite`), not from sub-paths of `ts-utils-lite`.","wrong":"import { ValidationUtils } from 'ts-utils-lite/validation';","symbol":"ValidationUtils","correct":"import { ValidationUtils } from 'ts-validation-lite';"}],"quickstart":{"code":"import { Injectable } from '@angular/core';\nimport {\n  StringUtils,\n  DateUtils,\n  ArrayUtils,\n  ObjectUtils,\n  NumberUtils,\n  ValidationUtils,\n  IdUtils,\n  CookieUtils,\n  StorageUtils\n} from 'ts-utils-lite';\n\n@Injectable({ providedIn: 'root' })\nexport class MyService {\n  constructor(\n    private str: StringUtils,\n    private date: DateUtils,\n    private arr: ArrayUtils,\n    private obj: ObjectUtils,\n    private num: NumberUtils,\n    private val: ValidationUtils,\n    private id: IdUtils,\n    private cookie: CookieUtils,\n    private storage: StorageUtils\n  ) { }\n  \n  runExamples(): void {\n    // String Utils\n    console.log('Slugify:', this.str.slugify('Hello World Example'));       // 'hello-world-example'\n    \n    // Date Utils\n    console.log('Formatted Date:', this.date.format(new Date(), 'YYYY-MM-DD')); // e.g., '2026-04-24'\n    \n    // Array Utils\n    console.log('Unique Array:', this.arr.unique([1, 2, 2, 3, 1]));         // [1, 2, 3]\n    \n    // Object Utils\n    console.log('Deep Get:', this.obj.deepGet({a: {b: 42}}, 'a.b')); // 42\n    \n    // Number Utils\n    console.log('Formatted Currency:', this.num.formatCurrency(1234.56));      // '$1,234.56'\n    \n    // Validation Utils\n    console.log('Is Email:', this.val.isEmail('test@example.com'));  // true\n    \n    // ID Utils\n    console.log('Generated UUID:', this.id.uuid());                        // e.g., '550e8400-e29b-41d4-a716-446655440000'\n    \n    // Cookie Utils (requires browser environment)\n    if (typeof document !== 'undefined') {\n      this.cookie.set('theme', 'dark', 7);   // Set cookie for 7 days\n      console.log('Cookie \"theme\":', this.cookie.get('theme'));\n    }\n    \n    // Storage Utils (requires browser environment)\n    if (typeof localStorage !== 'undefined') {\n      this.storage.set('user', { name: 'John Doe', id: 123 }); // Set to localStorage\n      const user = this.storage.get('user');      // Get from localStorage\n      console.log('Stored User:', user);\n      this.storage.remove('user'); // Clean up\n    }\n  }\n}","lang":"typescript","description":"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."},"warnings":[{"fix":"Ensure you instantiate the utility class before calling its methods, or use dependency injection if applicable (e.g., `private str: StringUtils`).","message":"The utility functions are exposed via instantiable classes (e.g., `StringUtils`), not static methods on a namespace. Therefore, you must create an instance of the class (e.g., `new StringUtils()`) or inject it in frameworks like Angular to call its methods.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `import { StringUtils } from 'ts-string-lite';` for the dedicated string utilities package, and `import { StringUtils } from 'ts-utils-lite';` for the aggregated bundle.","message":"When importing individual sub-packages, the import path is the specific NPM package name (e.g., `ts-string-lite`), not a sub-path of `ts-utils-lite`. Mixing these import styles can lead to module resolution issues.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Wrap usage of `CookieUtils` and `StorageUtils` with checks for `typeof document !== 'undefined'` or `typeof localStorage !== 'undefined'` to ensure they only execute in browser contexts.","message":"CookieUtils and StorageUtils are designed for browser environments. Attempting to use them in a Node.js environment (e.g., server-side rendering without proper polyfills) will result in runtime errors due to undefined `document` or `localStorage` objects.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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\"`).","message":"Like many modern TypeScript libraries, `ts-utils-lite` likely transitioned to an ESM-first approach in its major versions (e.g., v2.x). Direct `require()` statements might not work correctly without proper CommonJS interoperability configuration.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"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();`.","cause":"Attempting to call `StringUtils` directly as a function or missing the `new` keyword when it's an instantiable class in a CommonJS context, or if the module resolution is incorrect.","error":"TypeError: StringUtils is not a constructor"},{"fix":"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';`.","cause":"The specific sub-package was imported but not installed, or the import path is incorrect.","error":"Module not found: Error: Can't resolve 'ts-string-lite' in '...'"},{"fix":"Create an instance of `StringUtils` first, then call the method on the instance: `const strUtils = new StringUtils(); strUtils.slugify('...');`","cause":"Attempting to call `StringUtils.slugify()` statically when `slugify` is an instance method (e.g., `new StringUtils().slugify()`).","error":"Property 'slugify' does not exist on type 'typeof StringUtils'. Did you mean 'StringUtils'?"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}