@kobayami/guards
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.0 • Public • Published

    @kobayami/guards

    Installation

    npm install --save @kobayami/guards

    Version and License

    Summary

    Some standard guards and exceptions:

    • Type erasure for null and undefined
    • Array, index and range guards
    • Standard exception declarations, such as illegal state, illegal argument or unsupported operation

    Usage Example

    import { assertPresent, assertEqualLength, illegalArgument } from "@kobayami/guards";
    
    function first<T>(array: T[]): T {
        return assertPresent(array[0]);
    }
    
    function mergeMap<T, U>(a: T[], b: T[], operation: (elemA: T, elemB: T): U): U[] {
        const length = assertEqualLength(a, b);
        const result: U[] = [];
        for (let index = 0; index < length; index++) {
            result.push(operation(a[index], b[index]));
        }
        return result;
    }
    
    function assertInt16(value: number): number {
        if (value !== Math.round(value) || (value < -32768) || (value > 32767)) 
            throw illegalArgument();
    }

    See Also

    Install

    npm i @kobayami/guards

    DownloadsWeekly Downloads

    12

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    15.3 kB

    Total Files

    8

    Last publish

    Collaborators

    • kobayami