{"id":19675292,"url":"https://github.com/snowflyt/zefyr","last_synced_at":"2026-06-09T04:33:22.372Z","repository":{"id":193079043,"uuid":"688063802","full_name":"Snowflyt/zefyr","owner":"Snowflyt","description":"Configurable and typesafe monkey patching for TypeScript","archived":false,"fork":false,"pushed_at":"2023-11-16T10:51:27.000Z","size":457,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-17T17:04:38.051Z","etag":null,"topics":["monkey-patching","prototype-chain","typescipt"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/zefyr","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/Snowflyt.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-09-06T15:15:54.000Z","updated_at":"2024-09-27T12:29:33.000Z","dependencies_parsed_at":"2023-11-13T05:25:00.077Z","dependency_job_id":"d103a32c-d831-4b5d-bbb9-daba4cc46d7c","html_url":"https://github.com/Snowflyt/zefyr","commit_stats":null,"previous_names":["snowfly-t/zefyr","snowflyt/zefyr"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Snowflyt%2Fzefyr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Snowflyt%2Fzefyr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Snowflyt%2Fzefyr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Snowflyt%2Fzefyr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Snowflyt","download_url":"https://codeload.github.com/Snowflyt/zefyr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240985241,"owners_count":19889034,"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":["monkey-patching","prototype-chain","typescipt"],"created_at":"2024-11-11T17:23:00.216Z","updated_at":"2025-11-22T04:03:05.255Z","avatar_url":"https://github.com/Snowflyt.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zefyr\n\nConfigurable and typesafe monkey patching for TypeScript.\n\n```typescript\nimport 'zefyr/patches';\n\n// blueAndGreen :: ['green', 'blue']\nconst blueAndGreen = words('red green blue').without('red');\nconsole.log(blueAndGreen); // ['green', 'blue']\n\nnew Date().format('yyyy-MM-dd'); // =\u003e '2023-09-01'\n((3).days + (2).hours).ago() // =\u003e Date(2023-08-29T21:00:00.000Z)\n\nconst arr = [1, 2, true, 'a'];\narr.last; // =\u003e 'a'\nconst wrongResult = [1, 2, false].sum(); // Throws an error at runtime. wrongResult :: never\nconst rightResult = [1, 2, 3].sum(); // =\u003e 6. rightResult :: number\n\nconst arr2 = [1, 2, undefined, 4, null, undefined]; // arr2 :: (number | null | undefined)[]\nconst arr3 = arr2.compact(); // arr3 :: number[]\n\n(54321).digits[0]; // =\u003e 1\n(54321).digits(7)[1]; // =\u003e 6 (in 7-base)\n-10.5.isPositive(); // =\u003e false\n\nconst obj = { a: 1, b: 2 };\nconst keys = Object.strictKeys(obj);\nfor (const key of keys) {\n  console.log(obj[key]); // No type error in TypeScript\n}\n\n'hello'.reverse(); // =\u003e 'olleh'\nconst light = 'red' as 'red' | 'green' | 'blue' | '';\nif (light.isNotEmpty()) {\n  const light2 = light; // light2 :: 'red' | 'green' | 'blue'\n  // ...\n}\n\nfor (const n of range(3)) {\n  console.log(n); // 0, 1, 2\n}\n```\n\n**Note:** Zefyr requires TypeScript 5.0 or above and ES2020 or later. Currently, only ES Modules are supported.\n\n## Installation\n\n### npm\n\n```bash\nnpm install zefyr\n```\n\n### yarn\n\n```bash\nyarn add zefyr\n```\n\n### pnpm\n\n```bash\npnpm add zefyr\n```\n\n## Usage\n\nThe simplest way to start using Zefyr is to import `zefyr/patches` in your project. It would automatically patch the global objects and prototypes, so you can use the extensions directly.\n\nAll patches are well-typed in TypeScript, as well as well-documented, you can explore them in your editor or IDE just like the built-in ones.\n\n```typescript\nimport 'zefyr/patches';\n```\n\nAll patches are optional, you can import only the patches you need.\n\n```typescript\nimport 'zefyr/patches/Array'; // Import patches for Array\nimport 'zefyr/patches/Number'; // Import patches for Number\nimport 'zefyr/patches/Date/format'; // Import patches for only Date#format\n```\n\nIf you dislike the Monkey Patching pattern, you can also import the patches as functions.\n\n```typescript\nimport { sum } from 'zefyr/Array'; // Note that `patches` is not included in the path\nimport isNegative from 'zefyr/Number/isNegative';\n```\n\nZefyr exports a `patch` function for easy patching. You can create your own patches using it.\n\n```typescript\nimport { patch } from 'zefyr';\n\n// Declarations are required to ensure type safety\ndeclare global {\n  interface Number {\n    double(): number;\n  }\n\n  function hello(): void;\n}\n\npatch(Number).with({ double: (n) =\u003e n * 2 });\npatch(globalThis).withStatic({ hello: () =\u003e console.log('Hello, world!') });\n\nconsole.log((42).double()); // =\u003e 84\nhello(); // =\u003e 'Hello, world!'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnowflyt%2Fzefyr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnowflyt%2Fzefyr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnowflyt%2Fzefyr/lists"}