NodeSecure / size-satisfies

Same as SemVer.satisfies but for file size!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Caution

This package has been migrated to the CLI workspaces

size-satisfies

version OpenSSF Scorecard MIT size build

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 @nodesecure/size-satisfies
# or
$ yarn add @nodesecure/size-satisfies

Usage example

import { strict } from "assert";
import sizeSatisfies from "size-satisfies";

const { strictEqual } = strict;

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.

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):

Gentilhomme
Gentilhomme

πŸ’» πŸ“– πŸ‘€ πŸ›‘οΈ πŸ›
Nicolas Hallaert
Nicolas Hallaert

πŸ“–
Tony Gorez
Tony Gorez

πŸ’» πŸ“– πŸ‘€
tekeuange23
tekeuange23

πŸ“–
Kouadio Fabrice Nguessan
Kouadio Fabrice Nguessan

🚧
clbcky
clbcky

⚠️

License

MIT

About

Same as SemVer.satisfies but for file size!

License:MIT License


Languages

Language:JavaScript 100.0%