Skip to content

Commit 6f4ae51

Browse files
authored
feat: browser端,将 is-type-of 包的依赖处理为 shim (#801)
1 parent db48560 commit 6f4ae51

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"tabWidth": 2,
5+
"useTabs": false,
6+
"printWidth": 80,
7+
"bracketSpacing": true,
8+
"arrowParens": "avoid"
9+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"utility": "./shims/utility.js",
1616
"crypto": "./shims/crypto/crypto.js",
1717
"fs": false,
18-
"child_process": false
18+
"child_process": false,
19+
"is-type-of": "./shims/is-type-of.js"
1920
},
2021
"scripts": {
2122
"build-change-log": "standard-version",

shims/is-type-of.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { Stream } = require('stream');
2+
const isArray = require('../lib/common/utils/isArray');
3+
4+
module.exports.string = function isString(obj) {
5+
return typeof obj === 'string';
6+
};
7+
8+
module.exports.array = isArray;
9+
10+
module.exports.buffer = Buffer.isBuffer;
11+
12+
function isStream(obj) {
13+
return obj instanceof Stream;
14+
}
15+
16+
module.exports.writableStream = function isWritableStream(obj) {
17+
return (
18+
isStream(obj) &&
19+
typeof obj._write === 'function' &&
20+
typeof obj._writableState === 'object'
21+
);
22+
};

0 commit comments

Comments
 (0)