Skip to content
Myr

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 file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

lines 1–3why, one step back
1import isPlainObject from 'is-plain-obj';
2import {safeNormalizeFileUrl} from '../arguments/file-url.js';3

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 4why, one step back
4export const normalizeParameters = (rawFile, rawArguments = [], rawOptions = {}) => {

Rename files (#977)ehmickybefore adoption4b2e316

line 5why, one step back
5 const filePath = safeNormalizeFileUrl(rawFile, 'First argument');

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 6–8why, one step back
6 const [commandArguments, options] = isPlainObject(rawArguments)
7 ? [[], rawArguments]8 : [rawArguments, rawOptions];

Rename files (#977)ehmickybefore adoption4b2e316

line 9why, one step back
9

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 10–11why, one step back
10 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 back
12 }
13

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 14–15why, one step back
14 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 back
16 }
17

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 18–21why, one step back
18 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 back
22 }
2324 if (!isPlainObject(options)) {25 throw new TypeError(`Last argument must be an options object: ${options}`);26 }27

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 28why, one step back
28 return [filePath, normalizedArguments, options];

Rename files (#977)ehmickybefore adoption4b2e316

line 29why, one step back
29};