@@ -46,3 +46,183 @@ export function stringifyWithLoopProtection(obj: any, replacer?: any, space?: an
4646 hasCircleProp,
4747 } ;
4848}
49+
50+ const toString = Object . prototype . toString ;
51+
52+ /**
53+ * Determine if a value is an Array
54+ *
55+ * @param {Object } val The value to test
56+ * @returns {boolean } True if value is an Array, otherwise false
57+ */
58+ export function isArray ( val ) {
59+ return toString . call ( val ) === '[object Array]' ;
60+ }
61+
62+ /**
63+ * Determine if a value is undefined
64+ *
65+ * @param {Object } val The value to test
66+ * @returns {boolean } True if the value is undefined, otherwise false
67+ */
68+ export function isUndefined ( val ) {
69+ return typeof val === 'undefined' ;
70+ }
71+
72+ /**
73+ * Determine if a value is a Buffer
74+ *
75+ * @param {Object } val The value to test
76+ * @returns {boolean } True if value is a Buffer, otherwise false
77+ */
78+ export function isBuffer ( val ) {
79+ return (
80+ val !== null &&
81+ ! isUndefined ( val ) &&
82+ val . constructor !== null &&
83+ ! isUndefined ( val . constructor ) &&
84+ typeof val . constructor . isBuffer === 'function' &&
85+ val . constructor . isBuffer ( val )
86+ ) ;
87+ }
88+
89+ /**
90+ * Determine if a value is an ArrayBuffer
91+ *
92+ * @param {Object } val The value to test
93+ * @returns {boolean } True if value is an ArrayBuffer, otherwise false
94+ */
95+ export function isArrayBuffer ( val ) {
96+ return toString . call ( val ) === '[object ArrayBuffer]' ;
97+ }
98+
99+ /**
100+ * Determine if a value is a FormData
101+ *
102+ * @param {Object } val The value to test
103+ * @returns {boolean } True if value is an FormData, otherwise false
104+ */
105+ export function isFormData ( val ) {
106+ return typeof FormData !== 'undefined' && val instanceof FormData ;
107+ }
108+
109+ /**
110+ * Determine if a value is a view on an ArrayBuffer
111+ *
112+ * @param {Object } val The value to test
113+ * @returns {boolean } True if value is a view on an ArrayBuffer, otherwise false
114+ */
115+ export function isArrayBufferView ( val ) {
116+ var result ;
117+ if ( typeof ArrayBuffer !== 'undefined' && ArrayBuffer . isView ) {
118+ result = ArrayBuffer . isView ( val ) ;
119+ } else {
120+ result = val && val . buffer && val . buffer instanceof ArrayBuffer ;
121+ }
122+ return result ;
123+ }
124+
125+ /**
126+ * Determine if a value is a String
127+ *
128+ * @param {Object } val The value to test
129+ * @returns {boolean } True if value is a String, otherwise false
130+ */
131+ export function isString ( val ) {
132+ return typeof val === 'string' ;
133+ }
134+
135+ /**
136+ * Determine if a value is a Number
137+ *
138+ * @param {Object } val The value to test
139+ * @returns {boolean } True if value is a Number, otherwise false
140+ */
141+ export function isNumber ( val ) {
142+ return typeof val === 'number' ;
143+ }
144+
145+ /**
146+ * Determine if a value is an Object
147+ *
148+ * @param {Object } val The value to test
149+ * @returns {boolean } True if value is an Object, otherwise false
150+ */
151+ export function isObject ( val ) {
152+ return val !== null && typeof val === 'object' ;
153+ }
154+
155+ /**
156+ * Determine if a value is a plain Object
157+ *
158+ * @param {Object } val The value to test
159+ * @return {boolean } True if value is a plain Object, otherwise false
160+ */
161+ export function isPlainObject ( val ) {
162+ if ( toString . call ( val ) !== '[object Object]' ) {
163+ return false ;
164+ }
165+
166+ var prototype = Object . getPrototypeOf ( val ) ;
167+ return prototype === null || prototype === Object . prototype ;
168+ }
169+
170+ /**
171+ * Determine if a value is a Date
172+ *
173+ * @param {Object } val The value to test
174+ * @returns {boolean } True if value is a Date, otherwise false
175+ */
176+ export function isDate ( val ) {
177+ return toString . call ( val ) === '[object Date]' ;
178+ }
179+
180+ /**
181+ * Determine if a value is a File
182+ *
183+ * @param {Object } val The value to test
184+ * @returns {boolean } True if value is a File, otherwise false
185+ */
186+ export function isFile ( val ) {
187+ return toString . call ( val ) === '[object File]' ;
188+ }
189+
190+ /**
191+ * Determine if a value is a Blob
192+ *
193+ * @param {Object } val The value to test
194+ * @returns {boolean } True if value is a Blob, otherwise false
195+ */
196+ export function isBlob ( val ) {
197+ return toString . call ( val ) === '[object Blob]' ;
198+ }
199+
200+ /**
201+ * Determine if a value is a Function
202+ *
203+ * @param {Object } val The value to test
204+ * @returns {boolean } True if value is a Function, otherwise false
205+ */
206+ export function isFunction ( val ) {
207+ return toString . call ( val ) === '[object Function]' ;
208+ }
209+
210+ /**
211+ * Determine if a value is a Stream
212+ *
213+ * @param {Object } val The value to test
214+ * @returns {boolean } True if value is a Stream, otherwise false
215+ */
216+ export function isStream ( val ) {
217+ return isObject ( val ) && isFunction ( val . pipe ) ;
218+ }
219+
220+ /**
221+ * Determine if a value is a URLSearchParams object
222+ *
223+ * @param {Object } val The value to test
224+ * @returns {boolean } True if value is a URLSearchParams object, otherwise false
225+ */
226+ export function isURLSearchParams ( val ) {
227+ return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams ;
228+ }
0 commit comments