{"id":26409086,"url":"https://github.com/santi100a/percentage-lib","last_synced_at":"2025-03-17T19:18:47.265Z","repository":{"id":196299705,"uuid":"695693661","full_name":"santi100a/percentage-lib","owner":"santi100a","description":"Santi's Powerful Percentage Function: Easily find percentages!","archived":false,"fork":false,"pushed_at":"2023-12-25T16:36:48.000Z","size":353,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-24T22:44:13.934Z","etag":null,"topics":["library","math","percentage","santi100a","statistics","typescript"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@santi100a/percentage-lib","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/santi100a.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null},"funding":{"github":"santi100a"}},"created_at":"2023-09-23T23:18:10.000Z","updated_at":"2024-01-16T20:58:50.000Z","dependencies_parsed_at":"2023-09-24T07:12:56.994Z","dependency_job_id":null,"html_url":"https://github.com/santi100a/percentage-lib","commit_stats":null,"previous_names":["santi100a/percentage-lib"],"tags_count":1,"template":false,"template_full_name":"santi100a/npm-library-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santi100a%2Fpercentage-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santi100a%2Fpercentage-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santi100a%2Fpercentage-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santi100a%2Fpercentage-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/santi100a","download_url":"https://codeload.github.com/santi100a/percentage-lib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244094273,"owners_count":20397020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","math","percentage","santi100a","statistics","typescript"],"created_at":"2025-03-17T19:18:46.410Z","updated_at":"2025-03-17T19:18:47.255Z","avatar_url":"https://github.com/santi100a.png","language":"JavaScript","funding_links":["https://github.com/sponsors/santi100a"],"categories":[],"sub_categories":[],"readme":"# Santi's Powerful Percentage Function\r\n\r\n[![Build Status][workflow badge]][repo actions]\r\n[![npm homepage][npm badge]][npm home]\r\n[![GitHub stars][stars badge]][repo url]\r\n[![License][license badge]][repo url]\r\n[![Bundlephobia stats][bundlephobia badge]][bundlephobia url]\r\n\r\n[workflow badge]: https://github.com/santi100a/percentage-lib/actions/workflows/ci.yml/badge.svg\r\n[npm badge]: https://img.shields.io/npm/v/@santi100a/percentage-lib\r\n[stars badge]: https://img.shields.io/github/stars/santi100a/percentage-lib.svg\r\n[license badge]: https://img.shields.io/github/license/santi100a/percentage-lib.svg\r\n[bundlephobia badge]: https://img.shields.io/bundlephobia/min/@santi100a/percentage-lib\r\n[npm home]: https://npmjs.org/package/@santi100a/percentage-lib\r\n[repo actions]: https://github.com/santi100a/percentage-lib/actions\r\n[repo url]: https://github.com/santi100a/percentage-lib\r\n[bundlephobia url]: https://bundlephobia.com/package/@santi100a/percentage-lib@latest\r\n\r\n- 🚀 Lightweight and fast\r\n- 👴 ES3-compliant\r\n- 💻 Portable between the browser and Node.js\r\n- 📘 Includes TypeScript definitions\r\n\r\n## What's this?\r\n\r\nThis is a lightweight, portable NPM package to take the percentage of any number.\r\nThe following is the fundamental equation of percentages:\r\n\r\n$$ P = \\frac{1}{100} \\cdot n \\cdot p $$\r\n\r\nIn this formula:\r\n\r\n- P represents the value of the percentage.\r\n- n represents the number over which the percentage calculation will take place.\r\n- p represents the percentage.\r\n\r\nIt's clearer if we look at an example:\r\n\r\n$$ \\frac{1}{100} \\times 300 \\times 20 = 60 $$\r\n\r\nThis means that 20% of 300 is equal to 60, which is indeed correct.\r\n\r\n## Installation\r\n\r\n- Via NPM: `npm install @santi100a/percentage-lib`\r\n- Via Yarn: `yarn add @santi100a/percentage-lib`\r\n- Via PNPM: `pnpm install @santi100a/percentage-lib`\r\n\r\n## API\r\n\r\n- `function percentage(num: number, percentage: number): number;`\r\n\r\n  Calculates the percentage of a given number.\r\n\r\n  | Name         | Type     | Description                                                 | Optional? | Default |\r\n  | ------------ | -------- | ----------------------------------------------------------- | --------- | ------- |\r\n  | `num`        | `number` | The number for which the percentage needs to be calculated. | No        | _N/A_   |\r\n  | `percentage` | `number` | The percentage value to calculate. Must be positive.        | No        | _N/A_   |\r\n\r\n  Returns the calculated percentage value.\r\n  Throws a `TypeError` If `num` is not a number or `percentage` is not a number.\r\n  Throws a `TypeError` If `percentage` is not positive.\r\n\r\n## Usage\r\n\r\n```typescript\r\nconst percentage = require('@santi100a/percentage-lib'); // CJS\r\nimport percentage from '@santi100a/percentage-lib'; // ESM\r\nimport percentage = require('@santi100a/percentage-lib'); // TypeScript\r\n\r\nconst result = percentage(50, 20);\r\nconsole.log(result); // Output: 10\r\n```\r\n\r\n## Contribute\r\n\r\nWanna contribute? [File an issue](https://github.com/santi100a/percentage-lib/issues) or [pull request](https://github.com/santi100a/percentage-lib/pulls)!\r\nLook at [the contribution instructions](CONTRIBUTING.md) and make sure you follow the [contribution Code of Conduct](CODE_OF_CONDUCT.md).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanti100a%2Fpercentage-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanti100a%2Fpercentage-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanti100a%2Fpercentage-lib/lists"}