size-satisfies
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Size-satisfies

version Maintenance MIT dep size

Same as SemVer.satisfies but for file size!

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i size-satisfies
# or
$ yarn add size-satisfies

Usage example

const { strictEqual } = require("assert").strict;
const sizeSatisfies = require("size-satisfies");

strictEqual(sizeSatisfies(">= 45KB", "20MB"), true);
strictEqual(sizeSatisfies("= 1MB", "1MB"), true);
strictEqual(sizeSatisfies("= 1MB", 2000), false);

The first argument of the sizeSatisfies method is the pattern with the operator + size. Available operators are >=, <=, >, <, =.

API

sizeSatisfies(pattern: string, size: number | string): boolean

When the size is a string we convert it to a bytes number. When the argument is a number we consider the value as bytes.

Invalid pattern will always return false.

License

MIT

Package Sidebar

Install

npm i size-satisfies

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

4.74 kB

Total Files

5

Last publish

Collaborators

  • fraxken