@azizbecha/strkit
Version:
strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.
27 lines • 852 B
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = countWords;
/**
* Counts the number of words in a string
*
* @param str - The string to count words in
* @returns The number of words
*
* @example
* countWords('Hello world'); // 2
* countWords('This is a test'); // 4
*/
function countWords(str) {
return str.trim().split(/\s+/).length;
}
});
//# sourceMappingURL=countWords.js.map