Skip to content

Commit

Permalink
update devDependencies
Browse files Browse the repository at this point in the history
Highlight: spaces -> tabs shinnn/eslint-config@e92384d
  • Loading branch information
shinnn committed Dec 6, 2017
1 parent 07bbee9 commit cc3446f
Show file tree
Hide file tree
Showing 5 changed files with 4,074 additions and 207 deletions.
7 changes: 5 additions & 2 deletions .editorconfig
Expand Up @@ -3,10 +3,13 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
indent_style = tab
tab_width = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.{md,yml}]
indent_style = space

[*.md]
trim_trailing_whitespace = false
122 changes: 60 additions & 62 deletions index.js
Expand Up @@ -12,69 +12,67 @@ const isPlainObj = require('is-plain-obj');
const PATH_ERROR = 'Expected a file or directory path to get its mode';

const confusingOptionNames = new Set([
'followSymlink',
'resolveSymlink',
'resolveSymlinks'
'followSymlink',
'resolveSymlink',
'resolveSymlinks'
]);

module.exports = function getMode(...args) {
return new Promise((resolve, reject) => {
const argLen = args.length;

if (argLen !== 1 && argLen !== 2) {
throw new TypeError(`Expected 1 or 2 arguments (path: String[, option: Object]), but got ${
argLen === 0 ? 'no' : argLen
} arguments.`);
}

const [path, option] = args;

if (typeof path !== 'string') {
throw new TypeError(`${PATH_ERROR}, but got a non-string value ${inspectWithKind(path)}.`);
}

if (path.length === 0) {
throw new Error(`${PATH_ERROR}, but got '' (empty string).`);
}

function cb(err, result) {
if (err) {
reject(err);
return;
}

resolve(result.mode);
}

if (argLen === 1) {
lstat(path, cb);
return;
}

if (!isPlainObj(option)) {
throw new TypeError(
`Expected an object to specify whether \`followSymlinks\` option is enabled or not, but got ${
inspectWithKind(option)
}.`
);
}

for (const optionName of confusingOptionNames) {
const val = option[optionName];

if (val !== undefined) {
throw new Error(`\`${optionName}\` option is not supported but ${
inspectWithKind(val)
} was provided for it. You mistook \`followSymlinks\` as it.`);
}
}

if (option.followSymlinks && typeof option.followSymlinks !== 'boolean') {
throw new TypeError(`Expected \`followSymlinks\` option to be a Boolean value, but got ${
inspectWithKind(option.followSymlinks)
}.`);
}

(option.followSymlinks ? stat : lstat)(path, cb);
});
return new Promise((resolve, reject) => {
const argLen = args.length;

if (argLen !== 1 && argLen !== 2) {
throw new TypeError(`Expected 1 or 2 arguments (path: String[, option: Object]), but got ${
argLen === 0 ? 'no' : argLen
} arguments.`);
}

const [path, option] = args;

if (typeof path !== 'string') {
throw new TypeError(`${PATH_ERROR}, but got a non-string value ${inspectWithKind(path)}.`);
}

if (path.length === 0) {
throw new Error(`${PATH_ERROR}, but got '' (empty string).`);
}

function cb(err, result) {
if (err) {
reject(err);
return;
}

resolve(result.mode);
}

if (argLen === 1) {
lstat(path, cb);
return;
}

if (!isPlainObj(option)) {
throw new TypeError(`Expected an object to specify whether \`followSymlinks\` option is enabled or not, but got ${
inspectWithKind(option)
}.`);
}

for (const optionName of confusingOptionNames) {
const val = option[optionName];

if (val !== undefined) {
throw new Error(`\`${optionName}\` option is not supported but ${
inspectWithKind(val)
} was provided for it. You mistook \`followSymlinks\` as it.`);
}
}

if (option.followSymlinks && typeof option.followSymlinks !== 'boolean') {
throw new TypeError(`Expected \`followSymlinks\` option to be a Boolean value, but got ${
inspectWithKind(option.followSymlinks)
}.`);
}

(option.followSymlinks ? stat : lstat)(path, cb);
});
};

0 comments on commit cc3446f

Please sign in to comment.