This repository has been archived by the owner on Feb 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 91b8c5e
Showing
10 changed files
with
1,502 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2020": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"airbnb-base" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 11, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-unused-vars": [ | ||
"error" | ||
], | ||
"max-len": [ | ||
"error", | ||
120 | ||
], | ||
"no-restricted-globals": "off", | ||
"no-restricted-syntax": "off", | ||
"no-unused-vars": "off", | ||
"prefer-rest-params": "off", | ||
"no-param-reassign": "off" | ||
}, | ||
"ignorePatterns": [ | ||
"dist/*", | ||
"node_modules/*", | ||
"_.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Packages | ||
node_modules/ | ||
|
||
# Log files | ||
yarn-error.log | ||
|
||
# Build directories | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# @almeidx/is-empty | ||
|
||
Checks if value is an empty object, collection, map, or set. | ||
|
||
Objects are considered empty if they have no own enumerable string keyed properties. | ||
|
||
Array-like values such as arguments objects, arrays, buffers, strings, or jQuery-like collections are considered empty if they have a length of 0. Similarly, maps and sets are considered empty if they have a size of 0. | ||
|
||
```js | ||
import isEmpty from '@almeidx/is-empty'; | ||
// or | ||
const isEmpty = require('@almeidx/is-empty'); | ||
|
||
isEmpty(null); | ||
// => true | ||
|
||
isEmpty(true); | ||
// => true | ||
|
||
isEmpty(1); | ||
// => true | ||
|
||
isEmpty([1, 2, 3]); | ||
// => false | ||
|
||
isEmpty({ 'a': 1 }); | ||
// => false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@almeidx/is-empty", | ||
"version": "1.0.0", | ||
"description": "Tiny millisecond conversion utility", | ||
"repository": "https://github.com/almeidx/is-empty.git", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"keywords": [ | ||
"is-empty", | ||
"empty", | ||
"length-check" | ||
], | ||
"author": "almeidx <almeidx@pm.me> (almeidx.me)", | ||
"scripts": { | ||
"build": "rimraf dist && tsc", | ||
"lint": "eslint src --ext ts", | ||
"lint:fix": "eslint src --ext ts --fix", | ||
"prepublish": "rimraf dist && tsc" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.11.2", | ||
"@typescript-eslint/eslint-plugin": "^3.10.1", | ||
"@typescript-eslint/parser": "^3.10.1", | ||
"eslint": "^7.4.0", | ||
"eslint-config-airbnb-base": "^14.2.0", | ||
"eslint-plugin-import": "2.21.2", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.0.3" | ||
}, | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import * as util from 'util'; | ||
|
||
const getRawTag = (value: any): string => { | ||
const isOwn = Object.prototype.hasOwnProperty.call(value, Symbol.toStringTag); | ||
const tag = value[Symbol.toStringTag]; | ||
|
||
let unmasked = false; | ||
try { | ||
value[Symbol.toStringTag] = undefined; | ||
unmasked = true; | ||
} catch {} // eslint-disable-line no-empty | ||
|
||
const result = Object.prototype.toString.call(value); | ||
if (unmasked) { | ||
if (isOwn) { | ||
value[Symbol.toStringTag] = tag; | ||
} else { | ||
delete value[Symbol.toStringTag]; | ||
} | ||
} | ||
return result; | ||
}; | ||
|
||
const getTag = (value: any): string => { | ||
if (value == null) { | ||
return value === undefined ? '[object Undefined]' : '[object Null]'; | ||
} | ||
return (Symbol.toStringTag in Object(value)) | ||
? getRawTag(value) | ||
: Object.prototype.toString.call(value); | ||
}; | ||
|
||
const isFunction = (value: any): boolean => { | ||
if (value == null || (typeof value !== 'object' && typeof value !== 'function')) return false; | ||
|
||
const tag = getTag(value); | ||
return tag === '[object Function]' | ||
|| tag === '[object GeneratorFunction]' | ||
|| tag === '[object AsyncFunction]' | ||
|| tag === '[object Proxy]'; | ||
}; | ||
|
||
function isPrototype(value: any) { | ||
const valProto = value && value.constructor; | ||
return value === (typeof valProto === 'function' && valProto.prototype) || Object.prototype; | ||
} | ||
|
||
const overArg = ( | ||
func: (...args: any[]) => any, | ||
transform: any, | ||
// eslint-disable-next-line function-paren-newline | ||
): (...args: any[]) => any => function recursive(arg) { | ||
return func(transform(arg)); | ||
}; | ||
|
||
const baseKeys = (object: any) => { | ||
if (!isPrototype(object)) return overArg(Object.keys, Object)(object); | ||
|
||
const result = []; | ||
for (const key in Object(object)) { | ||
if (Object.prototype.hasOwnProperty.call(object, key) && key !== 'constructor') result.push(key); | ||
} | ||
return result; | ||
}; | ||
|
||
export const isEmpty = (value: any): boolean => { | ||
if (value == null) return true; | ||
|
||
if ( | ||
(value != null && typeof value.length === 'number' && !isFunction(value)) | ||
&& ( | ||
Array.isArray(value) | ||
|| typeof value === 'string' | ||
|| typeof value.splice === 'function' | ||
|| Buffer.isBuffer(value) | ||
|| util.types.isTypedArray(value) | ||
|| (typeof value === 'object' && getTag(value) === '[object Arguments]') | ||
) | ||
) return !value.length; | ||
|
||
const tag = getTag(value); | ||
if (tag === '[object Map]' || tag === '[object Set]') return !value.size; | ||
|
||
if (isPrototype(value)) return !baseKeys(value).length; | ||
|
||
for (const key in value) { | ||
if (Object.prototype.hasOwnProperty.call(value, key)) return false; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
export default isEmpty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"forceConsistentCasingInFileNames": true, | ||
"importHelpers": true, | ||
"noUnusedLocals": false, | ||
"removeComments": true, | ||
"module": "commonjs", | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"target": "es2019", | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"declaration": true | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
] | ||
} |
Oops, something went wrong.