@zerodep/string-words
v2.0.11
Published
A utility to convert a string into an array of words
Downloads
20
Readme
@zerodep/string-words
A utility to split a sentence of words into an array of those words and remove punctuation. Non-string values will cause a ZeroDepError
to be thrown.
Full documentation is available at the zerodep.app page.
Examples
All @zerodep packages support both ESM and CJS.
import { stringWords } from '@zerodep/string-words';
// or
const { stringWords } = require('@zerodep/string-words');
Using Default Space Separator
stringWords('California'); // ["California"]
stringWords('3.14 Pi'); // ["3.14", "Pi"]
stringWords("I'll be there for you. How about you?"); // ["I'll", "be", "there", "for", "you", "How", "about", "you"]
stringWords(''); // []
Using Custom Separator
stringWords('this_is_a_snake_case_string', '_'); // ["this", "is", "a", "snake", "case", "string"]
Unsuccessful Response
stringWords({ not: 'a string' }); // throws ZeroDepError: Value is not a string