JSPM

  • Created
  • Published
  • Downloads 6922
  • Score
    100M100P100Q136373F
  • License MIT

Is the input (plain object, array, string or whatever) not empty?

Package Exports

  • util-nonempty

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (util-nonempty) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

util-nonempty

ESLint on airbnb-base with caveats

Is the input (plain object, array, string or whatever) not empty?

Minimum Node version required Link to npm page Build Status Coverage bitHound Overall Score bitHound Dependencies View dependencies as 2D chart bitHound Dev Dependencies Known Vulnerabilities Downloads/Month Test in browser MIT License

Table of Contents

Install

npm i util-nonempty
// consume as a CommonJS require:
const nonEmpty = require('util-nonempty')
// or as ES module:
import nonEmpty from 'util-nonempty'

// then call as a function, pass it anything:
console.log(nonEmpty('a'))

Here's what you'll get:

Type Key in package.json Path Size
Main export - CommonJS version, transpiled to ES5, contains require and module.exports main dist/util-nonempty.cjs.js 757 B
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import/export. module dist/util-nonempty.esm.js 604 B
UMD build for browsers, transpiled, minified, containing iife's and has all dependencies baked-in browser dist/util-nonempty.umd.js 865 B

⬆  back to top

Purpose

I want a quick utility function, to be able to detect is the input not empty.

nonEmpty('z')
// => true

nonEmpty('')
// => false

nonEmpty(['a'])
// => true

nonEmpty([123])
// => true

nonEmpty([[[[[[[[[[[]]]]]]]]]]])
// => false

nonEmpty({a: 'a'})
// => true

nonEmpty({})
// => false

var f = function () { return 'z' }
nonEmpty(f)
// => false (answer is instantly false if input is not array, plain object or string)

If you want to check non-emptiness of complex nested trees of objects, arrays and strings (like parsed HTML AST), you need a library which can recursively traverse that. There are two options:

  • If you want to check for strict emptiness, that is [] or {} is empty, but {aaa: ' \n\n\n ', ' \t'} is not, see posthtml-ast-is-empty
  • If your "emptiness" definition is "everything that String.trim()'s to an empty string'" (this includes tabs, spaces and line breaks for example, but not letters), see posthtml-ast-contains-only-empty-space.

⬆  back to top

API

Anything-in, Boolean-out.

Contributing

Hi! 99% of people in the society are passive - consumers. They wait for others to take action, they prefer to blend in. The remaining 1% are proactive citizens who will do something rather than wait. If you are one of that 1%, you're in luck because I am the same and together we can make something happen.

  • If you want a new feature in this package or you would like to change some of its functionality, raise an issue on this repo. Also, you can email me. Just let it out.

  • If you tried to use this library but it misbehaves, or you need an advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo. Alternatively, you can email me.

  • If you don't like the code in here and would like to give advice about how something could be done better, please do. Same drill - GitHub issues or email, your choice.

  • If you would like to add or change some features, just fork it, hack away, and file a pull request. I'll do my best to merge it quickly. Code style is airbnb-base, only without semicolons. If you use a good code editor, it will pick up the established ESLint setup.

⬆  back to top

Licence

MIT License (MIT)

Copyright © 2018 Codsen Ltd, Roy Revelt