Merge pull request #535 from kingdavidmartins/add-isObject
Add isObject
This commit is contained in:
19
snippets/isObject.md
Normal file
19
snippets/isObject.md
Normal file
@ -0,0 +1,19 @@
|
||||
### isObject
|
||||
|
||||
Returns a boolean determining if the passed value is an object or not.
|
||||
|
||||
Uses the `Object` constructor to create an object wrapper for the given value.
|
||||
If the value is `null` or `undefined`, create and return an empty object. Οtherwise, return an object of a type that corresponds to the given value.
|
||||
|
||||
```js
|
||||
const isObject = obj => obj === Object(obj);
|
||||
```
|
||||
|
||||
```js
|
||||
isObject([1, 2, 3, 4]); // true
|
||||
isObject([]); // true
|
||||
isObject(['Hello!']); // true
|
||||
isObject({ a:1 }); // true
|
||||
isObject({}); // true
|
||||
isObject(true); // false
|
||||
```
|
||||
@ -84,6 +84,7 @@ isFunction:type,function
|
||||
isLowerCase:string,utility
|
||||
isNull:type
|
||||
isNumber:type,math
|
||||
isObject:type,object
|
||||
isPrime:math
|
||||
isPrimitive:type,function,array,string
|
||||
isPromiseLike:type,function,promise
|
||||
|
||||
2
test/decapitalize/decapitalize.js
Normal file
2
test/decapitalize/decapitalize.js
Normal file
@ -0,0 +1,2 @@
|
||||
module.exports = decapitalize = ([first, ...rest], upperRest = false) =>
|
||||
first.toLowerCase() + (upperRest ? rest.join('').toUpperCase() : rest.join(''));
|
||||
13
test/decapitalize/decapitalize.test.js
Normal file
13
test/decapitalize/decapitalize.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
const test = require('tape');
|
||||
const decapitalize = require('./decapitalize.js');
|
||||
|
||||
test('Testing decapitalize', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof decapitalize === 'function', 'decapitalize is a Function');
|
||||
//t.deepEqual(decapitalize(args..), 'Expected');
|
||||
//t.equal(decapitalize(args..), 'Expected');
|
||||
//t.false(decapitalize(args..), 'Expected');
|
||||
//t.throws(decapitalize(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
4
test/flattenDepth/flattenDepth.js
Normal file
4
test/flattenDepth/flattenDepth.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = flattenDepth = (arr, depth = 1) =>
|
||||
depth != 1
|
||||
? arr.reduce((a, v) => a.concat(Array.isArray(v) ? flattenDepth(v, depth - 1) : v), [])
|
||||
: arr.reduce((a, v) => a.concat(v), []);
|
||||
13
test/flattenDepth/flattenDepth.test.js
Normal file
13
test/flattenDepth/flattenDepth.test.js
Normal file
@ -0,0 +1,13 @@
|
||||
const test = require('tape');
|
||||
const flattenDepth = require('./flattenDepth.js');
|
||||
|
||||
test('Testing flattenDepth', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof flattenDepth === 'function', 'flattenDepth is a Function');
|
||||
//t.deepEqual(flattenDepth(args..), 'Expected');
|
||||
//t.equal(flattenDepth(args..), 'Expected');
|
||||
//t.false(flattenDepth(args..), 'Expected');
|
||||
//t.throws(flattenDepth(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
1
test/isObject/isObject.js
Normal file
1
test/isObject/isObject.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = isObject = obj => obj === Object(obj);
|
||||
19
test/isObject/isObject.test.js
Normal file
19
test/isObject/isObject.test.js
Normal file
@ -0,0 +1,19 @@
|
||||
const test = require('tape');
|
||||
const isObject = require('./isObject.js');
|
||||
|
||||
test('Testing isObject', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof isObject === 'function', 'isObject is a Function');
|
||||
|
||||
t.true(isObject([1, 2, 3, 4]), 'isObject([1, 2, 3, 4]) is a object');
|
||||
t.true(isObject([]), 'isObject([]) is a object');
|
||||
t.true(isObject({ a:1 }), 'isObject({ a:1 }) is a object');
|
||||
t.false(isObject(true), 'isObject(true) is not a object');
|
||||
|
||||
//t.deepEqual(isObject(args..), 'Expected');
|
||||
//t.equal(isObject(args..), 'Expected');
|
||||
//t.false(isObject(args..), 'Expected');
|
||||
//t.throws(isObject(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user