Skip to content

Commit

Permalink
refactor: remove is-plain-obj
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayllyz committed Aug 6, 2024
1 parent abd9fd0 commit f3d6edf
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/arguments/specific.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {debuglog} from 'node:util';
import isPlainObject from 'is-plain-obj';
import isPlainObject from '../utils/is-plain-object.js';
import {STANDARD_STREAMS_ALIASES} from '../utils/standard-stream.js';

// Some options can have different values for `stdout`/`stderr`/`fd3`.
Expand Down
2 changes: 1 addition & 1 deletion lib/methods/bind.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isPlainObject from 'is-plain-obj';
import isPlainObject from '../utils/is-plain-object.js';
import {FD_SPECIFIC_OPTIONS} from '../arguments/specific.js';

// Deep merge specific options like `env`. Shallow merge the other ones.
Expand Down
2 changes: 1 addition & 1 deletion lib/methods/create.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isPlainObject from 'is-plain-obj';
import isPlainObject from '../utils/is-plain-object.js';
import {normalizeParameters} from './parameters.js';
import {isTemplateString, parseTemplates} from './template.js';
import {execaCoreSync} from './main-sync.js';
Expand Down
2 changes: 1 addition & 1 deletion lib/methods/parameters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isPlainObject from 'is-plain-obj';
import isPlainObject from '../utils/is-plain-object.js';
import {safeNormalizeFileUrl} from '../arguments/file-url.js';

// The command `arguments` and `options` are both optional.
Expand Down
2 changes: 1 addition & 1 deletion lib/methods/template.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ChildProcess} from 'node:child_process';
import isPlainObject from 'is-plain-obj';
import isPlainObject from '../utils/is-plain-object.js';
import {isUint8Array, uint8ArrayToString} from '../utils/uint-array.js';

// Check whether the template string syntax is being used
Expand Down
2 changes: 1 addition & 1 deletion lib/pipe/setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isPlainObject from 'is-plain-obj';
import isPlainObject from '../utils/is-plain-object.js';
import {normalizePipeArguments} from './pipe-arguments.js';
import {handlePipeArgumentsError} from './throw.js';
import {waitForBothSubprocesses} from './sequence.js';
Expand Down
6 changes: 3 additions & 3 deletions lib/stdio/type.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {isStream as isNodeStream, isDuplexStream} from 'is-stream';
import isPlainObj from 'is-plain-obj';
import isPlainObject from '../utils/is-plain-object.js';
import {isUint8Array} from '../utils/uint-array.js';

// The `stdin`/`stdout`/`stderr` option can be of many types. This detects it.
Expand Down Expand Up @@ -117,13 +117,13 @@ const checkBooleanOption = (value, optionName) => {
const isGenerator = value => isAsyncGenerator(value) || isSyncGenerator(value);
export const isAsyncGenerator = value => Object.prototype.toString.call(value) === '[object AsyncGeneratorFunction]';
const isSyncGenerator = value => Object.prototype.toString.call(value) === '[object GeneratorFunction]';
const isTransformOptions = value => isPlainObj(value)
const isTransformOptions = value => isPlainObject(value)
&& (value.transform !== undefined || value.final !== undefined);

export const isUrl = value => Object.prototype.toString.call(value) === '[object URL]';
export const isRegularUrl = value => isUrl(value) && value.protocol !== 'file:';

const isFilePathObject = value => isPlainObj(value)
const isFilePathObject = value => isPlainObject(value)
&& Object.keys(value).length === 1
&& isFilePathString(value.file);
export const isFilePathString = file => typeof file === 'string';
Expand Down
6 changes: 3 additions & 3 deletions lib/transform/normalize.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isPlainObj from 'is-plain-obj';
import isPlainObject from '../utils/is-plain-object.js';
import {BINARY_ENCODINGS} from '../arguments/encoding-option.js';
import {TRANSFORM_TYPES} from '../stdio/type.js';
import {getTransformObjectModes} from './object-mode.js';
Expand Down Expand Up @@ -77,7 +77,7 @@ const normalizeDuplex = ({
};

const normalizeTransformStream = ({stdioItem, stdioItem: {value}, index, newTransforms, direction}) => {
const {transform, objectMode} = isPlainObj(value) ? value : {transform: value};
const {transform, objectMode} = isPlainObject(value) ? value : {transform: value};
const {writableObjectMode, readableObjectMode} = getTransformObjectModes(objectMode, index, newTransforms, direction);
return ({
...stdioItem,
Expand All @@ -92,7 +92,7 @@ const normalizeGenerator = ({stdioItem, stdioItem: {value}, index, newTransforms
binary: binaryOption = false,
preserveNewlines = false,
objectMode,
} = isPlainObj(value) ? value : {transform: value};
} = isPlainObject(value) ? value : {transform: value};
const binary = binaryOption || BINARY_ENCODINGS.has(encoding);
const {writableObjectMode, readableObjectMode} = getTransformObjectModes(objectMode, index, newTransforms, direction);
return {
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/is-plain-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function isPlainObject(v) {
return v && typeof v === 'object' && (Object.getPrototypeOf(v) === null || Object.getPrototypeOf(v) === Object.prototype);
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"figures": "^6.1.0",
"get-stream": "^9.0.0",
"human-signals": "^8.0.0",
"is-plain-obj": "^4.1.0",
"is-stream": "^4.0.1",
"npm-run-path": "^5.2.0",
"pretty-ms": "^9.0.0",
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/convert.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {text} from 'node:stream/consumers';
import {finished} from 'node:stream/promises';
import getStream from 'get-stream';
import isPlainObj from 'is-plain-obj';
import isPlainObject from '../../lib/utils/is-plain-object.js';
import {execa} from '../../index.js';
import {foobarString} from '../helpers/input.js';

Expand Down Expand Up @@ -62,7 +62,7 @@ export const assertSubprocessError = (t, subprocess, error) => assertPromiseErro
export const assertPromiseError = async (t, promise, error) => {
const thrownError = await t.throwsAsync(promise);

if (isPlainObj(error) && error.cause !== undefined) {
if (isPlainObject(error) && error.cause !== undefined) {
t.is(thrownError.cause, error.cause);
} else {
t.is(thrownError, error);
Expand Down

0 comments on commit f3d6edf

Please sign in to comment.