Skip to content

Commit

Permalink
feat: browser端,将 is-type-of 包的依赖处理为 shim (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
microJ committed Jun 4, 2020
1 parent db48560 commit 6f4ae51
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"useTabs": false,
"printWidth": 80,
"bracketSpacing": true,
"arrowParens": "avoid"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"utility": "./shims/utility.js",
"crypto": "./shims/crypto/crypto.js",
"fs": false,
"child_process": false
"child_process": false,
"is-type-of": "./shims/is-type-of.js"
},
"scripts": {
"build-change-log": "standard-version",
Expand Down
22 changes: 22 additions & 0 deletions shims/is-type-of.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { Stream } = require('stream');
const isArray = require('../lib/common/utils/isArray');

module.exports.string = function isString(obj) {
return typeof obj === 'string';
};

module.exports.array = isArray;

module.exports.buffer = Buffer.isBuffer;

function isStream(obj) {
return obj instanceof Stream;
}

module.exports.writableStream = function isWritableStream(obj) {
return (
isStream(obj) &&
typeof obj._write === 'function' &&
typeof obj._writableState === 'object'
);
};

0 comments on commit 6f4ae51

Please sign in to comment.