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 🙏

© 2026 – Pkg Stats / Ryan Hefner

isoneword

v1.1.7

Published

Checks if a value is a string containing exactly one word.

Readme

Usage

All time downloads:

Send Feedback

Checks if a value is a string containing exactly one word.

const isOneWord = require('isoneword');

console.log(isOneWord('hello'));     // true
console.log(isOneWord(' hello '));   // true (ignores leading/trailing space)
console.log(isOneWord('hello world')); // false
console.log(isOneWord(''));          // false
console.log(isOneWord(123));         // false

Here are additional usage examples covering different module systems (CommonJS and ES Modules) as well as various edge cases, including special characters, punctuation, and multi-line strings.

ES Modules (ESM) Usage

If the target repository uses "type": "module" in package.json or a modern bundler like Vite, Webpack, or Next, import the package using standard import syntax:

import isOneWord from 'isoneword';

console.log(isOneWord('OpenAI'));     // true

Comprehensive Validation Examples

The following test cases demonstrate how the package handles edge cases, numbers, punctuation, and hidden whitespace characters.

const isOneWord = require('isoneword');

// --- Standard Single Words ---
console.log(isOneWord('data'));        // true
console.log(isOneWord('supercalifragilisticexpialidocious')); // true

// --- Spaces and Trimming ---
console.log(isOneWord(' test '));      // true (surrounding spaces are ignored)
console.log(isOneWord('a b'));         // false (internal space creates two words)
console.log(isOneWord(' '));           // false (empty space strings return false)

// --- Special Characters and Punctuation ---
// Non-whitespace characters are treated as part of the single word string
console.log(isOneWord('semi-colon'));  // true (hyphens contain no whitespace)
console.log(isOneWord('user_name'));   // true (underscores contain no whitespace)
console.log(isOneWord('word!'));       // true (exclamation points contain no whitespace)
console.log(isOneWord('$100'));        // true 

// --- Hidden Whitespace (Tabs and Newlines) ---
console.log(isOneWord('word\tanother')); // false (contains a tab character)
console.log(isOneWord('first\nsecond')); // false (contains a newline character)
console.log(isOneWord('line1\rline2'));  // false (contains a carriage return character)

// --- Non-String Data Types ---
// Any non-string type will safely return false instead of throwing an error
console.log(isOneWord(null));          // false
console.log(isOneWord(undefined));     // false
console.log(isOneWord(42));            // false
console.log(isOneWord(['word']));      // false
console.log(isOneWord({ word: true })); // false

Integrating with Array Methods

Because the function returns a strict boolean, this can be passed directly into native js array methods like Array.prototype.filter() or Array.prototype.every().

const isOneWord = require('isoneword');

const tags = ['coding', 'open source', 'npm'];

// Filter a list to find only single-word tags
const singleWordTags = tags.filter(isOneWord);
console.log(singleWordTags); 
// Output: ['coding', 'npm']

// Check if an entire array consists of single words
const productIds = ['sku123', 'sku456', 'sku 789'];
const allValidIds = productIds.every(isOneWord);
console.log(allValidIds); 
// Output: false (because 'sku 789' contains a space)