npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

is-string-and-not-blank

v0.0.2

Published

3x as fast as `is-whitespace` and `whitespace-regex` thanks to `is-string-blank`. This package is a simple function that accepts an argument and returns `true` if it is a string AND it is not blank. Supports Node and Browser environments.

Downloads

484,897

Readme

is-string-and-not-blank

build status code coverage code style styled with prettier made with lass license npm downloads

3x as fast as is-whitespace and whitespace-regex thanks to is-string-blank. This package is a simple function that accepts an argument and returns true if it is a string AND it is not blank. Supports Node and Browser environments.

Table of Contents

Install

Node

npm:

npm install is-string-and-not-blank

yarn:

yarn add is-string-and-not-blank

Browser

See Browser usage below for more information.

Usage

Node

const isSANB = require('is-string-and-not-blank');

// returns false because it's a blank string
console.log(isSANB('    ')); // false

// returns true because it's a string and is not blank
console.log(isSANB('foo')); // true

// returns false because it's not a string
console.log(isSANB([])); // false

// returns false because it's not a string
console.log(isSANB([ 'test', 'test', 'test'])); // false

// returns true because it's a string and it is not blank
console.log(isSANB(' foo ')); // true

Browser

VanillaJS

The browser-ready bundle is only 566 bytes (minified and gzipped).

<script src="https://unpkg.com/is-string-and-not-blank"></script>
<script type="text/javascript">
  (function() {
    // returns false because it's a blank string
    console.log(isSANB('    ')); // false

    // returns true because it's a string and is not blank
    console.log(isSANB('foo')); // true

    // returns false because it's not a string
    console.log(isSANB([])); // false

    // returns false because it's not a string
    console.log(isSANB([ 'test', 'test', 'test'])); // false

    // returns true because it's a string and it is not blank
    console.log(isSANB(' foo ')); // true
  });
</script>

Bundler

If you're using something like browserify, webpack, or rollup, then install the package as you would with Node above.

Background

I made this after running into a bug with Firefox Klar/Focus, specifically related to underscore.string exposing s as the global, and that WebView overriding the global variable s. See mozilla-mobile/focus-android#4295, epeli/underscore.string#523, and epeli/underscore.string#415.

Also, using underscore.string just for its s.isBlank function is not preferable, and is-whitespace, and all other solutions did not save me the stress of having to type out if (typeof foo === 'string' && !isBlank(foo)).

This is a simple package that returns true if and only if the argument passed is a String and it is not blank, otherwise it returns false. No more false positives for arguments that are Arrays or other types (which for some reason other authors did not consider...?).

Other packages out there solve this problem similarly, however they do not return the same conditional test:

  • is-whitespace - you would need to further supplement this via if (typeof str === 'string' && !isWhitespace(str))
  • is-string-blank - same as is-whitespace above
  • is-blank - same as is-whitespace and is-string-blank above

Benchmark

See the test folder for a benchmark check integrated with the tests.

ℹ whitespace-regex  x 44,939,232 ops/sec ±2.44% (85 runs sampled)
ℹ is-string-and-not-blank x 145,034,505 ops/sec ±2.33% (86 runs sampled)

Contributors

| Name | Website | | -------------- | -------------------------- | | Nick Baugh | http://niftylettuce.com/ |

License

MIT © Nick Baugh