|
| 1 | +# `size-satisfies` |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/@nodesecure/size-satisfies) |
| 4 | +[](https://api.securityscorecards.dev/projects/github.com/NodeSecure/cli) |
| 6 | +[](https://github.com/NodeSecure/cli/blob/master/workspaces/size-satisfies/LICENSE) |
| 7 | + |
| 8 | +[](https://github.com/NodeSecure/cli/actions?query=workflow%3A%22Node.js+CI%22) |
| 9 | + |
| 10 | +Same as SemVer.satisfies but for file size! |
| 11 | + |
| 12 | +## Requirements |
| 13 | + |
| 14 | +- [Node.js](https://nodejs.org/en/) v18 or higher |
| 15 | + |
| 16 | +## Getting Started |
| 17 | + |
| 18 | +This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com). |
| 19 | + |
| 20 | +```bash |
| 21 | +$ npm i @nodesecure/size-satisfies |
| 22 | +# or |
| 23 | +$ yarn add @nodesecure/size-satisfies |
| 24 | +``` |
| 25 | + |
| 26 | +## Usage example |
| 27 | + |
| 28 | +```js |
| 29 | +import { strict } from "assert"; |
| 30 | +import sizeSatisfies from "size-satisfies"; |
| 31 | + |
| 32 | +const { strictEqual } = strict; |
| 33 | + |
| 34 | +strictEqual(sizeSatisfies(">= 45KB", "20MB"), true); |
| 35 | +strictEqual(sizeSatisfies("= 1MB", "1MB"), true); |
| 36 | +strictEqual(sizeSatisfies("= 1MB", 2000), false); |
| 37 | +``` |
| 38 | + |
| 39 | +The first argument of the `sizeSatisfies` method is the pattern with the operator + size. Available operators are `>=`, `<=`, `>`, `<`, `=`. |
| 40 | + |
| 41 | +## API |
| 42 | + |
| 43 | +### sizeSatisfies(pattern: string, size: number | string): boolean |
| 44 | + |
| 45 | +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. |
| 46 | + |
| 47 | +Invalid pattern will always return **false**. |
| 48 | + |
| 49 | +## Contributors ✨ |
| 50 | + |
| 51 | +<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --> |
| 52 | + |
| 53 | +[](#contributors-) |
| 54 | + |
| 55 | +<!-- ALL-CONTRIBUTORS-BADGE:END --> |
| 56 | + |
| 57 | +Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): |
| 58 | + |
| 59 | +<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> |
| 60 | +<!-- prettier-ignore-start --> |
| 61 | +<!-- markdownlint-disable --> |
| 62 | +<table> |
| 63 | + <tbody> |
| 64 | + <tr> |
| 65 | + <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/thomas-gentilhomme/"><img src="https://avatars.githubusercontent.com/u/4438263?v=4?s=100" width="100px;" alt="Gentilhomme"/><br /><sub><b>Gentilhomme</b></sub></a><br /><a href="https://github.com/NodeSecure/size-satisfies/commits?author=fraxken" title="Code">💻</a> <a href="https://github.com/NodeSecure/size-satisfies/commits?author=fraxken" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/size-satisfies/pulls?q=is%3Apr+reviewed-by%3Afraxken" title="Reviewed Pull Requests">👀</a> <a href="#security-fraxken" title="Security">🛡️</a> <a href="https://github.com/NodeSecure/size-satisfies/issues?q=author%3Afraxken" title="Bug reports">🐛</a></td> |
| 66 | + <td align="center" valign="top" width="14.28%"><a href="https://github.com/Rossb0b"><img src="https://avatars.githubusercontent.com/u/39910164?v=4?s=100" width="100px;" alt="Nicolas Hallaert"/><br /><sub><b>Nicolas Hallaert</b></sub></a><br /><a href="https://github.com/NodeSecure/size-satisfies/commits?author=Rossb0b" title="Documentation">📖</a></td> |
| 67 | + <td align="center" valign="top" width="14.28%"><a href="http://tonygo.dev"><img src="https://avatars.githubusercontent.com/u/22824417?v=4?s=100" width="100px;" alt="Tony Gorez"/><br /><sub><b>Tony Gorez</b></sub></a><br /><a href="https://github.com/NodeSecure/size-satisfies/commits?author=tony-go" title="Code">💻</a> <a href="https://github.com/NodeSecure/size-satisfies/commits?author=tony-go" title="Documentation">📖</a> <a href="https://github.com/NodeSecure/size-satisfies/pulls?q=is%3Apr+reviewed-by%3Atony-go" title="Reviewed Pull Requests">👀</a></td> |
| 68 | + <td align="center" valign="top" width="14.28%"><a href="https://github.com/tekeuange23"><img src="https://avatars.githubusercontent.com/u/35274201?v=4?s=100" width="100px;" alt="tekeuange23"/><br /><sub><b>tekeuange23</b></sub></a><br /><a href="https://github.com/NodeSecure/size-satisfies/commits?author=tekeuange23" title="Documentation">📖</a></td> |
| 69 | + <td align="center" valign="top" width="14.28%"><a href="https://github.com/fabnguess"><img src="https://avatars.githubusercontent.com/u/72697416?v=4?s=100" width="100px;" alt="Kouadio Fabrice Nguessan"/><br /><sub><b>Kouadio Fabrice Nguessan</b></sub></a><br /><a href="#maintenance-fabnguess" title="Maintenance">🚧</a></td> |
| 70 | + <td align="center" valign="top" width="14.28%"><a href="https://github.com/clbcky"><img src="https://avatars.githubusercontent.com/u/113340767?v=4?s=100" width="100px;" alt="clbcky"/><br /><sub><b>clbcky</b></sub></a><br /><a href="https://github.com/NodeSecure/size-satisfies/commits?author=clbcky" title="Tests">⚠️</a></td> |
| 71 | + </tr> |
| 72 | + </tbody> |
| 73 | +</table> |
| 74 | + |
| 75 | +<!-- markdownlint-restore --> |
| 76 | +<!-- prettier-ignore-end --> |
| 77 | + |
| 78 | +<!-- ALL-CONTRIBUTORS-LIST:END --> |
| 79 | + |
| 80 | +## License |
| 81 | + |
| 82 | +MIT |
0 commit comments