JSPM

  • Created
  • Published
  • Downloads 839
  • Score
    100M100P100Q91479F
  • License MIT

Assertions and typeguards

Package Exports

  • @httpx/assert
  • @httpx/assert/package.json

Readme

@httpx/assert

Assertions and typeguards as primitives

npm changelog codecov bundles node browserslist size maintainability downloads license

Install

$ npm install @httpx/assert
$ yarn add @httpx/assert
$ pnpm add @httpx/assert

Features

Wip

Documentation

👉 Official website, Github Readme or generated api doc

Usage

import { isPainObject, assertPlainObject } from '@httpx/assert';

isPlainObject({cool: true}); // true
isPlainObject(new Promise()); // false
assertPlainObject({});
import { assertStrNotEmpty, isStrNotEmpty } from '@httpx/assert';

isStrNotEmpty(''); // false
isStrNotEmpty(' '); // false: trim by default
isStrNotEmpty(' ', false); // true: disbable trim
assertStrNotEmpty('');

Uuid

Supported uuid versions are: 1, 3, 4 and 5.

import { isUuid, isUuidV1, isUuidV3, isUuidV4, isUuidV5 } from "@httpx/assert";
import { assertUuid, assertUuidV1, assertUuidV3, assertUuidV4, assertUuidV5 } from "@httpx/assert";
import { getUuidVersion } from '@httpx/assert';

// Without version
isUuid('90123e1c-7512-523e-bb28-76fab9f2f73d'); // is valid uuid v1, 3, 4 or 5
assertUuid('90123e1c-7512-523e-bb28-76fab9f2f73d');

// With version
isUuid('90123e1c-7512-523e-bb28-76fab9f2f73d', 5);
assertUuid('90123e1c-7512-523e-bb28-76fab9f2f73d', 5);
assertUuidV5('90123e1c-7512-523e-bb28-76fab9f2f73d')
isUuidV4('d9428888-122b-11e1-b85c-61cd3cbb3210'); // or isUuidV1(''), isUuidV3(''), isUuidV5('');

// Utils
getUuidVersion('90123e1c-7512-523e-bb28-76fab9f2f73d'); // 5

Barcode

Supported barcodes is currently limited to Ean13

import { isEan13 } from "@httpx/assert";
import { assertEan13 } from "@httpx/assert";

isEan13('1234567890128'); // 👈 will check digit too
assertEan13('1234567890128');

Bundle size

Code and bundler have been tuned to target a minimal compressed footprint for the browser.

ESM individual imports are tracked by a size-limit configuration.

Scenario Size (compressed)
All typeguards, assertions and helpers ~ 900b

For CJS usage (not recommended) track the size on bundlephobia.

Compatibility

ES2021 / Node 16+ and the following browsers: Chrome 96+, Firefox 90+, Edge 19+, Safari 12+, Opera 77+.

Edge tests are run with @vercel/edge-runtime

Browser builds follows the .browserslistrc configuration.

For older browsers:

  • Most frontend frameworks can transpile the library (ie: nextjs...)

Contributors

Contributions are warmly appreciated. Have a look to the CONTRIBUTING document.

Sponsors

If my OSS work brightens your day, let's take it to new heights together! Sponsor, coffee, or star – any gesture of support fuels my passion to improve. Thanks for being awesome! 🙏❤️

Special thanks to

Jetbrains logo Jetbrains logo
JetBrains Embie.be

License

MIT © belgattitude and contributors.