Sha256: b407a546e2bc210cdfa2685e6802743fadbbb11cdb646e1c489d8f507cf53acc

Contents?: true

Size: 1.07 KB

Versions: 64

Compression:

Stored size: 1.07 KB

Contents

/**
 * @license
 * Copyright (c) 2016, Contributors
 * SPDX-License-Identifier: ISC
 */
// take an un-split argv string and tokenize it.
export function tokenizeArgString(argString) {
    if (Array.isArray(argString)) {
        return argString.map(e => typeof e !== 'string' ? e + '' : e);
    }
    argString = argString.trim();
    let i = 0;
    let prevC = null;
    let c = null;
    let opening = null;
    const args = [];
    for (let ii = 0; ii < argString.length; ii++) {
        prevC = c;
        c = argString.charAt(ii);
        // split on spaces unless we're in quotes.
        if (c === ' ' && !opening) {
            if (!(prevC === ' ')) {
                i++;
            }
            continue;
        }
        // don't split the string if we're in matching
        // opening or closing single and double quotes.
        if (c === opening) {
            opening = null;
        }
        else if ((c === "'" || c === '"') && !opening) {
            opening = c;
        }
        if (!args[i])
            args[i] = '';
        args[i] += c;
    }
    return args;
}

Version data entries

64 entries across 61 versions & 7 rubygems

Version Path
rapid_stack-0.2.0 templates/frontend/node_modules/karma/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
rapid_stack-0.2.0 templates/frontend/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
rapid_stack-0.1.1 templates/FrontEnd/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
rapid_stack-0.1.1 templates/FrontEnd/node_modules/karma/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
rapid_stack-0.1.0 templates/FrontEnd/node_modules/karma/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
rapid_stack-0.1.0 templates/FrontEnd/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
trusty-cms-6.3.1 node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.26 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/yargs-parser/build/lib/tokenize-arg-string.js