{"id":21331434,"url":"https://github.com/eibens/modulo","last_synced_at":"2025-03-16T00:42:44.078Z","repository":{"id":62422120,"uuid":"374978881","full_name":"eibens/modulo","owner":"eibens","description":"The mathematical modulo operation in TypeScript for Deno.","archived":false,"fork":false,"pushed_at":"2021-12-06T21:57:36.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T07:53:02.147Z","etag":null,"topics":["deno","math","modulo","quotient","typescript","utility"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/eibens.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-08T11:08:45.000Z","updated_at":"2021-12-06T21:56:25.000Z","dependencies_parsed_at":"2022-11-01T17:45:30.602Z","dependency_job_id":null,"html_url":"https://github.com/eibens/modulo","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eibens%2Fmodulo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eibens%2Fmodulo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eibens%2Fmodulo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eibens%2Fmodulo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eibens","download_url":"https://codeload.github.com/eibens/modulo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243809848,"owners_count":20351407,"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":["deno","math","modulo","quotient","typescript","utility"],"created_at":"2024-11-21T22:33:07.288Z","updated_at":"2025-03-16T00:42:44.059Z","avatar_url":"https://github.com/eibens.png","language":"TypeScript","readme":"# modulo\n\n[modulo](#) implements the mathematical [modulo operation] in TypeScript for\n[Deno](https://deno.land).\n\n\u003c!-- badges --\u003e\n\n[![License](https://img.shields.io/github/license/eibens/modulo?color=informational)](LICENSE)\n[![deno.land/x](https://img.shields.io/badge/x/modulo-informational?logo=deno\u0026label)](https://deno.land/x/modulo)\n[![Repository](https://img.shields.io/github/v/tag/eibens/modulo?label\u0026logo=github)](https://github.com/eibens/modulo)\n[![ci](https://github.com/eibens/modulo/actions/workflows/ci.yml/badge.svg)](https://github.com/eibens/modulo/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/eibens/modulo/branch/master/graph/badge.svg?token=OV98O91EJ1)](https://codecov.io/gh/eibens/modulo)\n\n\u003c!-- /badges --\u003e\n\n# Motivation\n\nJavaScript has no native support for true modulo. The `%` operator works as\nmodulo for positive numbers, but not negative ones. For example, `-1 % 3 = -1`\ncompared to `-1 mod 3 = 2`. If you need the latter, you can either use this\nmodule, or memorize this [modulo formula for JavaScript]:\n\n```\nx mod n = ((x % n) + n) % n\n```\n\n# Usage\n\nThe `modulo` function calculates `m = x mod n`:\n\n```ts\nimport { modulo } from \"https://deno.land/x/modulo/mod.ts\";\n\nconst x = -1;\nconst n = 3;\nconst m = modulo(x, n);\n\nconsole.assert(m === 2);\n```\n\nThe `quotient` function calculates `q = floor(x / n)`.\n\n```ts\nimport { quotient } from \"https://deno.land/x/modulo/mod.ts\";\n\nconst x = -1;\nconst n = 3;\nconst q = quotient(x, n);\n\nconsole.assert(q === -1);\n```\n\nThe `decompose` function calculates `(q, m)`. `q`, `m`, and `n` together define\nthe original value `x = q * n + m`:\n\n```ts\nimport { decompose } from \"https://deno.land/x/modulo/mod.ts\";\n\nconst x = -1;\nconst n = 3;\nconst [q, m] = decompose(x, n);\n\nconsole.assert(x == q * n + m);\n```\n\n[modulo operation]: https://en.wikipedia.org/wiki/Modulo_operation\n[modulo formula for JavaScript]: https://web.archive.org/web/20090717035140if_/javascript.about.com/od/problemsolving/a/modulobug.htm\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feibens%2Fmodulo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feibens%2Fmodulo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feibens%2Fmodulo/lists"}