@consumidor-positivo/ts-utils - v1.13.0
    Preparing search index...

    @consumidor-positivo/ts-utils - v1.13.0

    TypeScript Utils Logo

    @consumidor-positivo/ts-utils

    TypeScript utilities library for Consumidor Positivo projects.

    npm install @consumidor-positivo/ts-utils
    
    import { range } from '@consumidor-positivo/ts-utils';

    // Generate an array of sequential numbers
    const numbers = range(5);
    console.log(numbers); // [0, 1, 2, 3, 4]

    The library also provides React hooks that can be imported separately. These hooks are optional and require React as a peer dependency.

    import { usePersistedState } from '@consumidor-positivo/ts-utils/hooks';

    function UserPreferences() {
    // Persist state in localStorage (default)
    const [preferences, setPreferences, clearPreferences] = usePersistedState('user-preferences', {
    theme: 'light',
    fontSize: 14
    });

    // Persist state in sessionStorage
    const [sessionData, setSessionData] = usePersistedState('session-data',
    { isLoggedIn: true },
    { storage: 'session' }
    );

    const toggleTheme = () => {
    setPreferences({
    ...preferences,
    theme: preferences?.theme === 'light' ? 'dark' : 'light'
    });
    };

    return (
    <div>
    <p>Current theme: {preferences?.theme}</p>
    <button onClick={toggleTheme}>Toggle Theme</button>
    <button onClick={clearPreferences}>Reset Preferences</button>
    </div>
    );
    }

    See the documentation for more detailed examples and API reference.

    This library is designed to contain only generic utility functions that can be safely used in client-side applications. When contributing, please adhere to these important principles:

    • No business logic: This library should not contain any business-specific logic or rules.
    • No internal requests: Do not include API calls or requests to internal services.
    • No sensitive code: Avoid including any sensitive information or algorithms.
    • Client-side safe: All utilities should be appropriate for use in browser environments.

    The purpose of this library is to provide reusable, generic utility functions that help with common programming tasks across different Consumidor Positivo projects.

    Please read our Contributing Guide for details on our development process, Git workflows, and how to submit pull requests.

    To generate the library documentation, run:

    npm run docs
    

    The documentation will be generated in the docs/ directory.

    To generate and view the documentation on a local server, run:

    npm run docs:serve
    

    This will start a local server and the documentation will be available at http://localhost:3000.

    To build both the library and documentation, run:

    npm run build:all
    

    This library uses Vitest for testing. Here are the available test commands:

    npm test
    
    npm run test:watch
    
    npm run test:coverage
    
    npm run test:ui
    

    Proprietary - Consumidor Positivo