NASA Proceeds to Mars

    string-incr
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.5 • Public • Published

    string-incr

    Increment or decrement string with number

    Install

    $ npm install --save string-incr
    

    Signature

    stringIncr(str: string | number, firstAppend?: string | number): string;
    stringDecr(str: string | number, firstAppend?: string | number): string;
    • str: String|Number = '' : The string
    • firstAppend: String|Number = ' 2': The append content for the first number (when first parameter don't finish with number)

    Examples

    import { stringIncr, stringDecr } from "string-inc";
    
    stringIncr("Hello world 42");
    //=> 'Hello world 43'
    
    stringDecr("Hello world 42");
    //=> 'Hello world 41'

    stringIncr

    import { stringIncr } from "string-inc";
    
    stringIncr("Hello world");
    //=> 'Hello world 2'
    
    stringIncr("Hello world 2");
    //=> 'Hello world 3'
    
    stringIncr("Hello world 42");
    //=> 'Hello world 43'

    stringDecr

    All exemples for stringIncr work for stringDecr

    import { stringDecr } from "string-inc";
    
    stringIncr("Hello world");
    //=> 'Hello world -1'
    
    stringIncr("Hello world 2");
    //=> 'Hello world 1'
    
    stringIncr("Hello world 42");
    //=> 'Hello world 41'

    Only last numbers are incremented

    stringIncr("Hello world42");
    //=> 'Hello world43'
    
    stringIncr("Hello 42 world99");
    //=> 'Hello 42 world100'
    
    stringIncr("Hello-world-42");
    //=> 'Hello-world-43'
    
    stringIncr("Hello-world-4242");
    //=> 'Hello-world-4243'

    Change append text for the first number

    stringIncr("Hello world", "-1"); // With string, finish with number
    //=> 'Hello world-1'
    
    stringIncr("Hello world", "-2");
    //=> 'Hello world-2'
    
    stringIncr("Hello world", 1); // Use only number (auto add space before)
    //=> 'Hello world 1'
    
    stringIncr("Hello world", 42);
    //=> 'Hello world 42'
    
    stringIncr("Hello world", "#"); // Or use only separator
    //=> 'Hello world#2'
    
    stringIncr("Hello world 2", "-2"); // The second parameter is only for the first number !
    //=> 'Hello world 3'

    Change log

    • 3.0.0 Add decrement
    • 2.0.0 Typescript support

    Install

    npm i string-incr

    DownloadsWeekly Downloads

    52

    Version

    3.0.5

    License

    MIT

    Unpacked Size

    6.38 kB

    Total Files

    9

    Last publish

    Collaborators

    • apoutchika