Neglected Puppy Market

    @innotrade/enapso-args

    1.0.1 • Public • Published

    Enapso Smart Arguments Processor

    You can either pass a single object as arguments or the arguments in the defined order.

    Why to use the Enapso Smart Arguments Processor?

    You avoid unexpected results due to wrong or missing arguments or due to wrong argument order. You can specify defaults for missing arguments and valdiate your arguments against a given schema.

    Installation

    npm i @innotrade/enapso-args --save
    

    Usage

    Initialization

    const
        { EnapsoArguments } = require('@innotrade/enapso-args')
        ;
    
    global.enargs = new EnapsoArguments();
    global.enGetArgs = enargs.getArgs;

    Arg Validation Schema

    const
        schemaSingleStringArg = {
            args: [
                {
                    "identifier": "text",
                    "type": "string",
                    "required": false,
                    "default": "default value",
                    "minLength": 0,
                    "maxLength": 20
                }
            ]
        };

    Argument Validation

    function demoSingleStringArg(/*text*/) {
        let args = enGetArgs(arguments, schemaSingleStringArg, logValidationViolation);
        console.log('demoSingleStringArg: ' + args.text);
    }
    
    function demo() {
        demoSingleStringArg("Test");
        demoSingleStringArg(1);
        demoSingleStringArg(true);
        demoSingleStringArg();
    }

    Output

    demoSingleStringArg: Test
    Error: Argument 'text' must be of type 'string' but is of type 'number'. Value: 1
    demoSingleStringArg: 1
    Error: Argument 'text' must be of type 'string' but is of type 'boolean'. Value: true
    demoSingleStringArg: true
    demoSingleStringArg: default value
    

    Install

    npm i @innotrade/enapso-args

    DownloadsWeekly Downloads

    47

    Version

    1.0.1

    License

    Apache-2.0

    Unpacked Size

    17.3 kB

    Total Files

    7

    Last publish

    Collaborators

    • asheshgoplani
    • myasir786
    • alexander-schulze