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

2.0.7 • Public • Published

@zerodep/guard-object

version language types license

CodeFactor Known Vulnerabilities

A run-time guard to require a value to be an object; 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 { guardObject } from '@zerodep/guard-object';
// or
const { guardObject } = require('@zerodep/guard-object');

Successful Cases

guardObject({ an: 'object' }); // void

Unsuccessful Cases

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

Readme

Keywords

Package Sidebar

Install

npm i @zerodep/guard-object

Homepage

zerodep.app

Weekly Downloads

0

Version

2.0.7

License

MIT

Unpacked Size

7.77 kB

Total Files

7

Last publish

Collaborators

  • cdepage