@zerodep/guard-string
TypeScript icon, indicating that this package has built-in type declarations

2.0.7 • Public • Published

@zerodep/guard-string

version language types license

CodeFactor Known Vulnerabilities

A run-time guard to require a value to be a string; it will throw a ZeroDepError if the guard fails.

Full documentation is available at the zerodep.app page.

Examples

All @zerodep packages support both ESM and CJS.

import { guardString } from '@zerodep/guard-string';
// or
const { guardString } = require('@zerodep/guard-string');

Successful Cases

guardString(''); // void
guardString('a string'); // void

Unsuccessful Cases

guardString([]); // throws ZeroDepError: Value is not a string
guardString(['a', 'b', 'c']); // throws ZeroDepError: Value is not a string
guardString(1000n); // throws ZeroDepError: Value is not a string
guardString(true); // throws ZeroDepError: Value is not a string
guardString(new Date()); // throws ZeroDepError: Value is not a string
guardString(new Error('message')); // throws ZeroDepError: Value is not a string
guardString(3.14); // throws ZeroDepError: Value is not a string
guardString(() => 'function'); // throws ZeroDepError: Value is not a string
guardString(42); // throws ZeroDepError: Value is not a string
guardString(
  new Map([
    ['a', 1],
    ['b', 2],
  ])
); // throws ZeroDepError: Value is not a string
guardString(null); // throws ZeroDepError: Value is not a string
guardString({ an: 'object' }); // throws ZeroDepError: Value is not a string
guardString(new Promise(() => {})); // throws ZeroDepError: Value is not a string
guardString(/[regex]+/gi); // throws ZeroDepError: Value is not a string
guardString(new Set([1, 2, 3])); // throws ZeroDepError: Value is not a string
guardString(Symbol()); // throws ZeroDepError: Value is not a string
guardString(new Int32Array(2)); // throws ZeroDepError: Value is not a string
guardString(undefined); // throws ZeroDepError: Value is not a string

Readme

Keywords

Package Sidebar

Install

npm i @zerodep/guard-string

Homepage

zerodep.app

Weekly Downloads

0

Version

2.0.7

License

MIT

Unpacked Size

7.49 kB

Total Files

7

Last publish

Collaborators

  • cdepage