@x-oasis/is-empty 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @x-oasis/is-empty
2
+
3
+ _test value is `NaN`, `undefined`, `null`, `''`, `[]` and `{}` _
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ npm i @x-oasis/is-empty
9
+ ```
10
+
11
+ ## How to use
12
+
13
+ ```typescript
14
+ import isEmpty from '@x-oasis/is-empty'
15
+ ```
16
+
17
+ ## How to run test
18
+
19
+ ```bash
20
+ $ pnpm test
21
+ ```
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: any) => boolean;
2
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./is-empty.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./is-empty.cjs.development.js')
8
+ }
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
7
+ var toString = _interopDefault(require('@x-oasis/to-string'));
8
+
9
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
10
+ var index = (function (value) {
11
+ if (value == null) return true;
12
+ if (Array.isArray(value)) return !value.length;
13
+ var type = toString(value);
14
+ if (type === '[object Map]' || type === '[object Set]') return !value.size;
15
+ for (var key in value) {
16
+ if (hasOwnProperty.call(value, key)) {
17
+ return false;
18
+ }
19
+ }
20
+ if (type === '[object Number]') return false;
21
+ if (type === '[object Boolean]') return false;
22
+ return true;
23
+ });
24
+
25
+ exports.default = index;
26
+ //# sourceMappingURL=is-empty.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-empty.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["import toString from '@x-oasis/to-string';\n\n// https://github.com/lodash/lodash/blob/main/src/isEmpty.ts\n// https://stackoverflow.com/a/53751866\n\nconst hasOwnProperty = Object.prototype.hasOwnProperty;\n\nexport default (value: any) => {\n // null or undefined\n if (value == null) return true;\n if (Array.isArray(value)) return !value.length;\n\n const type = toString(value);\n if (type === '[object Map]' || type === '[object Set]') return !value.size;\n for (const key in value) {\n if (hasOwnProperty.call(value, key)) {\n return false;\n }\n }\n if (type === '[object Number]') return false;\n if (type === '[object Boolean]') return false;\n return true;\n};\n"],"names":["hasOwnProperty","Object","prototype","value","Array","isArray","length","type","toString","size","key","call"],"mappings":";;;;;;;;AAKA,IAAMA,cAAc,GAAGC,MAAM,CAACC,SAAS,CAACF,cAAc;AAEtD,aAAe,UAACG,KAAU;EAExB,IAAIA,KAAK,IAAI,IAAI,EAAE,OAAO,IAAI;EAC9B,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE,OAAO,CAACA,KAAK,CAACG,MAAM;EAE9C,IAAMC,IAAI,GAAGC,QAAQ,CAACL,KAAK,CAAC;EAC5B,IAAII,IAAI,KAAK,cAAc,IAAIA,IAAI,KAAK,cAAc,EAAE,OAAO,CAACJ,KAAK,CAACM,IAAI;EAC1E,KAAK,IAAMC,GAAG,IAAIP,KAAK,EAAE;IACvB,IAAIH,cAAc,CAACW,IAAI,CAACR,KAAK,EAAEO,GAAG,CAAC,EAAE;MACnC,OAAO,KAAK;;;EAGhB,IAAIH,IAAI,KAAK,iBAAiB,EAAE,OAAO,KAAK;EAC5C,IAAIA,IAAI,KAAK,kBAAkB,EAAE,OAAO,KAAK;EAC7C,OAAO,IAAI;AACb,CAAC;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=(e=require("@x-oasis/to-string"))&&"object"==typeof e&&"default"in e?e.default:e,t=Object.prototype.hasOwnProperty;exports.default=function(e){if(null==e)return!0;if(Array.isArray(e))return!e.length;var o=r(e);if("[object Map]"===o||"[object Set]"===o)return!e.size;for(var n in e)if(t.call(e,n))return!1;return"[object Number]"!==o&&"[object Boolean]"!==o};
2
+ //# sourceMappingURL=is-empty.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-empty.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["import toString from '@x-oasis/to-string';\n\n// https://github.com/lodash/lodash/blob/main/src/isEmpty.ts\n// https://stackoverflow.com/a/53751866\n\nconst hasOwnProperty = Object.prototype.hasOwnProperty;\n\nexport default (value: any) => {\n // null or undefined\n if (value == null) return true;\n if (Array.isArray(value)) return !value.length;\n\n const type = toString(value);\n if (type === '[object Map]' || type === '[object Set]') return !value.size;\n for (const key in value) {\n if (hasOwnProperty.call(value, key)) {\n return false;\n }\n }\n if (type === '[object Number]') return false;\n if (type === '[object Boolean]') return false;\n return true;\n};\n"],"names":["hasOwnProperty","Object","prototype","value","Array","isArray","length","type","toString","size","key","call"],"mappings":"6JAKMA,EAAiBC,OAAOC,UAAUF,wCAExBG,GAEd,GAAa,MAATA,EAAe,OAAO,EAC1B,GAAIC,MAAMC,QAAQF,GAAQ,OAAQA,EAAMG,OAExC,IAAMC,EAAOC,EAASL,GACtB,GAAa,iBAATI,GAAoC,iBAATA,EAAyB,OAAQJ,EAAMM,KACtE,IAAK,IAAMC,KAAOP,EAChB,GAAIH,EAAeW,KAAKR,EAAOO,GAC7B,OAAO,EAGX,MAAa,oBAATH,GACS,qBAATA"}
@@ -0,0 +1,20 @@
1
+ import toString from '@x-oasis/to-string';
2
+
3
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
4
+ var index = (function (value) {
5
+ if (value == null) return true;
6
+ if (Array.isArray(value)) return !value.length;
7
+ var type = toString(value);
8
+ if (type === '[object Map]' || type === '[object Set]') return !value.size;
9
+ for (var key in value) {
10
+ if (hasOwnProperty.call(value, key)) {
11
+ return false;
12
+ }
13
+ }
14
+ if (type === '[object Number]') return false;
15
+ if (type === '[object Boolean]') return false;
16
+ return true;
17
+ });
18
+
19
+ export default index;
20
+ //# sourceMappingURL=is-empty.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-empty.esm.js","sources":["../src/index.ts"],"sourcesContent":["import toString from '@x-oasis/to-string';\n\n// https://github.com/lodash/lodash/blob/main/src/isEmpty.ts\n// https://stackoverflow.com/a/53751866\n\nconst hasOwnProperty = Object.prototype.hasOwnProperty;\n\nexport default (value: any) => {\n // null or undefined\n if (value == null) return true;\n if (Array.isArray(value)) return !value.length;\n\n const type = toString(value);\n if (type === '[object Map]' || type === '[object Set]') return !value.size;\n for (const key in value) {\n if (hasOwnProperty.call(value, key)) {\n return false;\n }\n }\n if (type === '[object Number]') return false;\n if (type === '[object Boolean]') return false;\n return true;\n};\n"],"names":["hasOwnProperty","Object","prototype","value","Array","isArray","length","type","toString","size","key","call"],"mappings":";;AAKA,IAAMA,cAAc,GAAGC,MAAM,CAACC,SAAS,CAACF,cAAc;AAEtD,aAAe,UAACG,KAAU;EAExB,IAAIA,KAAK,IAAI,IAAI,EAAE,OAAO,IAAI;EAC9B,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE,OAAO,CAACA,KAAK,CAACG,MAAM;EAE9C,IAAMC,IAAI,GAAGC,QAAQ,CAACL,KAAK,CAAC;EAC5B,IAAII,IAAI,KAAK,cAAc,IAAIA,IAAI,KAAK,cAAc,EAAE,OAAO,CAACJ,KAAK,CAACM,IAAI;EAC1E,KAAK,IAAMC,GAAG,IAAIP,KAAK,EAAE;IACvB,IAAIH,cAAc,CAACW,IAAI,CAACR,KAAK,EAAEO,GAAG,CAAC,EAAE;MACnC,OAAO,KAAK;;;EAGhB,IAAIH,IAAI,KAAK,iBAAiB,EAAE,OAAO,KAAK;EAC5C,IAAIA,IAAI,KAAK,kBAAkB,EAAE,OAAO,KAAK;EAC7C,OAAO,IAAI;AACb,CAAC;;;;"}
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@x-oasis/is-empty",
3
+ "version": "0.1.20",
4
+ "description": "is-empty function",
5
+ "main": "dist/index.js",
6
+ "typings": "dist/index.d.ts",
7
+ "module": "dist/is-empty.esm.js",
8
+ "author": "",
9
+ "license": "ISC",
10
+ "devDependencies": {
11
+ "tsdx": "^0.14.1"
12
+ },
13
+ "dependencies": {
14
+ "@x-oasis/to-string": "^0.1.19"
15
+ },
16
+ "scripts": {
17
+ "build": "tsdx build --tsconfig tsconfig.build.json",
18
+ "clean": "rimraf ./dist",
19
+ "test": "vitest",
20
+ "compile": "tsc -p tsconfig.build.json"
21
+ }
22
+ }
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ import toString from '@x-oasis/to-string';
2
+
3
+ // https://github.com/lodash/lodash/blob/main/src/isEmpty.ts
4
+ // https://stackoverflow.com/a/53751866
5
+
6
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
7
+
8
+ export default (value: any) => {
9
+ // null or undefined
10
+ if (value == null) return true;
11
+ if (Array.isArray(value)) return !value.length;
12
+
13
+ const type = toString(value);
14
+ if (type === '[object Map]' || type === '[object Set]') return !value.size;
15
+ for (const key in value) {
16
+ if (hasOwnProperty.call(value, key)) {
17
+ return false;
18
+ }
19
+ }
20
+ if (type === '[object Number]') return false;
21
+ if (type === '[object Boolean]') return false;
22
+ return true;
23
+ };
@@ -0,0 +1,12 @@
1
+ import { expect, test } from 'vitest';
2
+ import isEmpty from '../src';
3
+
4
+ test('vitest', async () => {
5
+ expect(isEmpty({})).toBe(true);
6
+ expect(isEmpty([])).toBe(true);
7
+ expect(isEmpty(new Map())).toBe(true);
8
+ expect(isEmpty(new Set())).toBe(true);
9
+ expect(isEmpty(false)).toBe(false);
10
+ expect(isEmpty(0)).toBe(false);
11
+ expect(isEmpty(1)).toBe(false);
12
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../../tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "esModuleInterop": true
6
+ },
7
+
8
+ "include": [
9
+ "src/**/*"
10
+ ]
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "jsx": "react",
5
+ "esModuleInterop": true
6
+ }
7
+ }