A lightweight utility to check if a given value is a string.
- Zero dependencies: Lightweight and easy to integrate.
- Reliable type-checking: Handles edge cases such as
Object.create(null)
or string objects (new String()
). - Cross-platform: Works in Node.js, browsers, and other JavaScript environments.
- ESM and CJS support: Fully compatible with modern module systems.
You can install is-string-checker
using your favorite package manager:
# Using pnpm
pnpm add is-string-checker
# Using npm
npm install is-string-checker
# Using yarn
yarn add is-string-checker
Here's how to use the library in your project:
// CommonJS
const isString = require('is-string-checker');
// ES Modules
import isString from 'is-string-checker';
console.log(isString("hello")); // true
console.log(isString(new String("hello"))); // true
console.log(isString(123)); // false
console.log(isString(null)); // false
console.log(isString(undefined)); // false
Checks if the given value
is a string.
value
(any
): The value to check.
boolean
: Returnstrue
ifvalue
is a string; otherwise,false
.
If you want to contribute or run the project locally, follow these steps:
git clone https://github.com/angelabenavente/is-string-checker.git
cd is-string-checker
npm install
npm run test
npm run eslint
This project uses Jest for testing. To run the test suite, simply use:
npm run test
Example output:
PASS ./isString.test.js
✓ should return true for valid strings (10 ms)
✓ should return false for non-strings
...
Feel free to add more test cases in the test
file.
See CHANGELOG.md for a detailed history of changes.
Contributions are welcome! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a clear description of the changes.
See CONTRIBUTING.md for more details.
This project is licensed under the MIT License. Created with ❤️ by Ángela Benavente.
-
GitHub Repository: https://github.com/angelabenavente/is-string-checker
-
NPM Package: https://www.npmjs.com/package/is-string-checker