From 6f4ae5113df3c0ca26b4957a9aec6c811b85b257 Mon Sep 17 00:00:00 2001 From: microJ Date: Thu, 4 Jun 2020 13:54:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20browser=E7=AB=AF,=E5=B0=86=20is-type-of?= =?UTF-8?q?=20=E5=8C=85=E7=9A=84=E4=BE=9D=E8=B5=96=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=B8=BA=20shim=20(#801)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierrc | 9 +++++++++ package.json | 3 ++- shims/is-type-of.js | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .prettierrc create mode 100644 shims/is-type-of.js diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..6ed6b425e --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "semi": true, + "singleQuote": true, + "tabWidth": 2, + "useTabs": false, + "printWidth": 80, + "bracketSpacing": true, + "arrowParens": "avoid" +} diff --git a/package.json b/package.json index 957a05281..c6f9b822c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/shims/is-type-of.js b/shims/is-type-of.js new file mode 100644 index 000000000..3880a3e3e --- /dev/null +++ b/shims/is-type-of.js @@ -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' + ); +};