parameters.js
This file
Path
lib/methods/parameters.js
29 lines · 1.2 KiB · JavaScript
Last changed by
Upgrade xo (#980)ehmickybefore adoptionccfa412
History of this fileTake it
Rename files (#977)ehmickybefore adoption4b2e316
lines 1–3why, one step back1import isPlainObject from 'is-plain-obj';2import {safeNormalizeFileUrl} from '../arguments/file-url.js';3Upgrade xo (#980)ehmickybefore adoptionccfa412
line 4why, one step back4export const normalizeParameters = (rawFile, rawArguments = [], rawOptions = {}) => {Rename files (#977)ehmickybefore adoption4b2e316
line 5why, one step back5 const filePath = safeNormalizeFileUrl(rawFile, 'First argument');Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 6–8why, one step back6 const [commandArguments, options] = isPlainObject(rawArguments)7 ? [[], rawArguments]8 : [rawArguments, rawOptions];Rename files (#977)ehmickybefore adoption4b2e316
line 9why, one step back9Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 10–11why, one step back10 if (!Array.isArray(commandArguments)) {11 throw new TypeError(`Second argument must be either an array of arguments or an options object: ${commandArguments}`);Rename files (#977)ehmickybefore adoption4b2e316
lines 12–13why, one step back12 }13Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 14–15why, one step back14 if (commandArguments.some(commandArgument => typeof commandArgument === 'object' && commandArgument !== null)) {15 throw new TypeError(`Second argument must be an array of strings: ${commandArguments}`);Rename files (#977)ehmickybefore adoption4b2e316
lines 16–17why, one step back16 }17Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 18–21why, one step back18 const normalizedArguments = commandArguments.map(String);19 const nullByteArgument = normalizedArguments.find(normalizedArgument => normalizedArgument.includes('\0'));20 if (nullByteArgument !== undefined) {21 throw new TypeError(`Arguments cannot contain null bytes ("\\0"): ${nullByteArgument}`);Rename files (#977)ehmickybefore adoption4b2e316
lines 22–27why, one step back22 }2324 if (!isPlainObject(options)) {25 throw new TypeError(`Last argument must be an options object: ${options}`);26 }27Upgrade xo (#980)ehmickybefore adoptionccfa412
line 28why, one step back28 return [filePath, normalizedArguments, options];Rename files (#977)ehmickybefore adoption4b2e316
line 29why, one step back29};