{"id":19675320,"url":"https://github.com/snowflyt/xtensions","last_synced_at":"2026-06-16T07:32:07.606Z","repository":{"id":196328048,"uuid":"682463262","full_name":"Snowflyt/xtensions","owner":"Snowflyt","description":"Bring extensions to TypeScript","archived":false,"fork":false,"pushed_at":"2023-08-24T08:20:02.000Z","size":80,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-25T20:20:35.514Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/xtensions","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}},"created_at":"2023-08-24T08:16:45.000Z","updated_at":"2023-09-06T15:22:13.000Z","dependencies_parsed_at":"2023-09-24T14:11:30.842Z","dependency_job_id":null,"html_url":"https://github.com/Snowflyt/xtensions","commit_stats":null,"previous_names":["snowfly-t/xtensions"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Snowflyt%2Fxtensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Snowflyt%2Fxtensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Snowflyt%2Fxtensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Snowflyt%2Fxtensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Snowflyt","download_url":"https://codeload.github.com/Snowflyt/xtensions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240985239,"owners_count":19889032,"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":[],"created_at":"2024-11-11T17:23:09.543Z","updated_at":"2026-06-16T07:32:07.599Z","avatar_url":"https://github.com/Snowflyt.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Xtensions\n\nBring extensions to TypeScript.\n\n## Installation\n\n### npm\n\n```bash\nnpm install xtensions\n```\n\n### yarn\n\n```bash\nyarn add xtensions\n```\n\n### pnpm\n\n```bash\npnpm add xtensions\n```\n\n## Usage\n\nLet's use a minimal example to show how to use Xtensions.\n\n```ts\nimport { extension, extensions } from 'xtensions';\n\n// Define extension for string\nconst stringExtensions = extension('string', (s) =\u003e ({ // `s` is inferred to be string\n  emphasize: (level: number) =\u003e s + '!'.repeat(level),\n}));\n// Define extension for number\nconst numberExtensions = extension('number', (n) =\u003e ({ // `n` is inferred to be number\n  add: (x: number) =\u003e n + x,\n  double: () =\u003e n * 2,\n}));\n// Define extension for more complex objects\nconst intervalExtensions = extension({\n  start: 'Date | number',\n  end: 'Date | number',\n}, (i) =\u003e ({ // `i` is inferred to be { start: Date | number, end: Date | number }\n  duration: () =\u003e {\n    const start = typeof i.start === 'number' ? i.start : i.start.getTime();\n    const end = typeof i.end === 'number' ? i.end : i.end.getTime();\n    return end - start;\n  },\n}));\n\n// Create the extension function (which is usually named `ex`)\nconst ex = extensions.use(stringExtensions, numberExtensions, intervalExtensions);\n\n// `ex` would choose the correct extension based on the type of the argument\nconst interval = { start: new Date('2023-01-01'), end: new Date('2023-01-02') };\nconst duration = ex(interval).duration(); // 86400000\n// Note that when use `ex` on primitive types, they would be converted to boxed types.\n// For example, string -\u003e String, number -\u003e Number, boolean -\u003e Boolean, etc.\n// But don't worry, as TypeScript would infer the type correctly, so you won't forget to use `toString()` or `valueOf()`\n// to convert them back to primitive types.\nconst emphasized = ex('Hello').emphasize(3).toString(); // 'Hello!!!'\nconst doubled42 = ex(42).double().valueOf(); // 84\n// Once you use `ex` on something, it would extend all returned values of extension functions automatically\n// for chaining them.\nconst doubledDuration = ex(interval).duration().double(); // No need to use `ex(ex(interval).duration()).double()`\n```\n\nXtensions uses [ArkType](https://arktype.io/), a truly powerful and natural validator for TypeScript, to infer the type according to definition (like `'string'` -\u003e `string`, `{ start: 'Date | number', end: 'Date | number' }` -\u003e `{ start: Date | number; end: Date | number }`), and validate the types of input (i.e. choose the correct extension to use). You can visit [its website](https://arktype.io/) to learn more how to define more complex types for your extensions.\n\nYou can view the recommended way to use Xtensions in a real project in the `examples/` directory. It is recommended to start from `examples/basic`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnowflyt%2Fxtensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnowflyt%2Fxtensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnowflyt%2Fxtensions/lists"}