Skip to content

Commit

Permalink
feat: rewrite in TS, use named exports
Browse files Browse the repository at this point in the history
BREAKING CHANGE: previously, you'd consume like "import nonEmpty from ..." - now consume like
"import { nonEmpty } from ..."
  • Loading branch information
revelt committed Dec 23, 2020
1 parent 359c5ff commit 5cbaf96
Show file tree
Hide file tree
Showing 18 changed files with 433 additions and 306 deletions.
3 changes: 2 additions & 1 deletion packages/util-nonempty/.npmignore
@@ -1,4 +1,4 @@
# .... generated using www.npmjs.com/package/lect ....
# generated using codsen.com/os/lect
#
#
# __ ______ ______ ______
Expand All @@ -23,3 +23,4 @@ test
.prettierignore
rollup.config.js
testStats.md
tsconfig.json
2 changes: 1 addition & 1 deletion packages/util-nonempty/README.md
Expand Up @@ -34,7 +34,7 @@ npm i util-nonempty

```js
import { strict as assert } from "assert";
import nonEmpty from "util-nonempty";
import { nonEmpty } from "util-nonempty";

assert.equal(nonEmpty("z"), true);
assert.equal(nonEmpty(""), false);
Expand Down
2 changes: 1 addition & 1 deletion packages/util-nonempty/coverage/coverage-summary.json
@@ -1 +1 @@
{"total":{"lines":{"total":12,"covered":12,"skipped":0,"pct":100},"statements":{"total":12,"covered":12,"skipped":0,"pct":100},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":12,"covered":12,"skipped":0,"pct":100}}}
{"total":{"lines":{"total":8,"covered":8,"skipped":0,"pct":100},"statements":{"total":8,"covered":8,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":8,"covered":8,"skipped":0,"pct":100}}}
33 changes: 17 additions & 16 deletions packages/util-nonempty/dist/util-nonempty.cjs.js
Expand Up @@ -9,33 +9,34 @@

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var isPlainObject = require('lodash.isplainobject');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);

var isArr = Array.isArray;
function isStr(something) {
return typeof something === "string";
}
function isNum(something) {
return typeof something === "number";
}
var version = "2.10.0";

/* eslint @typescript-eslint/no-explicit-any:0, @typescript-eslint/explicit-module-boundary-types:0 */

function nonEmpty(input) {
if (arguments.length === 0 || input === undefined) {
// deliberate ==, catches undefined and null
if (input == null) {
return false;
}
if (isArr(input) || isStr(input)) {
return input.length > 0;

if (Array.isArray(input) || typeof input === "string") {
return !!input.length;
}

if (isPlainObject__default['default'](input)) {
return Object.keys(input).length > 0;
return !!Object.keys(input).length;
}
if (isNum(input)) {
return true;
}
return false;

return typeof input === "number";
}

module.exports = nonEmpty;
exports.nonEmpty = nonEmpty;
exports.version = version;

0 comments on commit 5cbaf96

Please sign in to comment.