{"id":18885920,"url":"https://github.com/studiohyperdrive/shortener","last_synced_at":"2025-04-14T21:31:02.229Z","repository":{"id":57163257,"uuid":"130606178","full_name":"studiohyperdrive/shortener","owner":"studiohyperdrive","description":"Light-weight JavaScript utility to create an url shortener with","archived":false,"fork":false,"pushed_at":"2018-10-11T14:54:10.000Z","size":46,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T10:21:16.623Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/studiohyperdrive.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":"2018-04-22T20:45:57.000Z","updated_at":"2021-05-21T22:52:41.000Z","dependencies_parsed_at":"2022-09-01T03:11:46.906Z","dependency_job_id":null,"html_url":"https://github.com/studiohyperdrive/shortener","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/studiohyperdrive%2Fshortener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/studiohyperdrive%2Fshortener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/studiohyperdrive%2Fshortener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/studiohyperdrive%2Fshortener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/studiohyperdrive","download_url":"https://codeload.github.com/studiohyperdrive/shortener/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248537003,"owners_count":21120687,"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-08T07:23:12.702Z","updated_at":"2025-04-14T21:31:01.870Z","avatar_url":"https://github.com/studiohyperdrive.png","language":"JavaScript","readme":"\u003ch1 align=\"center\"\u003e\nShortener\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@studiohyperdrive/shortener.svg?colorB=1C1676\"\u003e\u003c/a\u003e\n\u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/npm/dt/@studiohyperdrive/shortener.svg?colorB=785FC8\"\u003e\u003c/a\u003e\n\u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/bundlephobia/min/@studiohyperdrive/shortener.svg?colorB=82BBED\"\u003e\u003c/a\u003e\n\u003ca href=\"#\"\u003e\u003cimg src=\"https://img.shields.io/badge/coverage-100%25-green.svg?colorB=FB9ED8\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg?colorB=F342D7\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cb\u003eLight-weight JavaScript utility to create an url shortener with\u003c/b\u003e\n  \u003cbr\u003e\n  \u003csub\u003eOnly ~3.5kb, no external dependencies, supports NodeJS 6+ and ES2015+\u003c/sub\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\n-   **Lightweight:** ~3.5kb in size, vanilla JavaScript and no external dependencies 🐜\n-   **Fast:** generates 100 shortened urls in less than 5ms 🚤\n-   **Configurable:** lends ultimate control over the output format of the shortened urls 🛠️\n-   **Tested:** 100% code coverage 🎉\n-   **MIT Licensed:** free for personal and commercial use ❤️\n\n* * *\n\n## How to install\n\nInstall with:\n- NPM: `npm install @studiohyperdrive/shortener`\n- Yarn: `yarn add @studiohyperdrive/shortener`\n\n## How to use\n\n### CommonJS (Node 6+)\n\n```javascript\nconst Shortener = require(\"@studiohyperdrive/shortener\")\n```\n\n### ESModule  (ES2015+)\n\n```javascript\nimport Shortener from \"@studiohyperdrive/shortener\"\n```\n\n### Configuration\n\nAn instance of the shortener can be created by calling the constructor with a configuration.\n\n```javascript\nconst shortener = new Shortener(configuration)\n```\n\nThe following parameters are accepted in the configuration:\n\n| Key                         | Description                                                                                                                                                                                                                                                         | Default  |\n|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|\n| `target`\u003csup\u003erequired\u003c/sup\u003e | A valid url to append the shortened id to, by default the id is added at the end of the url. \u003cbr\u003e\u003cbr\u003e Optionally, you can pass a placeholder `{id}` to reposition the id anywhere in the url. \u003cbr\u003e Example: `https://short.er?id={0}` → `https://shorter?id=SP4C3`  | none     |\n| `length`                    | Length of the shortened id.                                                                                                                                                                                                                                         | 5        |\n| `alphabet`                  | Alphabet with allowed characters for generating the shortened id, \u003cbr\u003e you can also choose one of the included [presets](#presets).                                                                                                                                 | `base58` |\n\nExample:\n\n```javascript\nconst shortener = new Shortener({\n  target: \"https://short.er\"\n  length: 6,\n  alphabet: \"0123456789abcdefABCDEF\"\n})\n```\n\n### Presets\n\nThe `alphabet` parameter accepts multiple presets:\n\n| Name           | Value                                                            |\n| -------------- | ---------------------------------------------------------------- |\n| `alphanumeric` | `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789` |\n| `alphabetic`   | `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`           |\n| `numeric`      | `0123456789`                                                     |\n| `base58`       | `abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789`     |\n| `base56`       | `abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789`       |\n| `base32`       | `ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`                           |\n| `base16`       | `ABCDEF0123456789`                                               |\n\nExample:\n\n```javascript\nconst shortener = new Shortener({\n  target: \"https://short.er\"\n  alphabet: \"alphanumeric\"\n})\n```\n\n### `.shorten(url)`\n\nShortens a given url.\n\nExample:\n\n```javascript\nconst result = shortener.shorten(\"https://www.google.com\");\n```\n\n`result` output:\n\n```javascript\n{\n  id: \"6VYN9\",\n  original: \"https://www.google.com\",\n  target: \"https://short.er/6VYN9\"\n}\n```\n\n### `.getInfo()`\n\nGets information about the current configuration\n\nExample:\n\n```javascript\nconst info = shortener.getInfo();\n```\n\n`info` output:\n\n```javascript\n{\n  config: {\n    target: 'https://short.er',\n    length: 5,\n    alphabet: 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789'\n  },\n  collisionInfo: {\n    // The amount of unique shortened id's that can be generated\n    // with the current configuration of length \u0026 alphabet\n    possibilities: 656356768,\n\n    //The probability of generating a non-unique shortened id\n    probability: 1.5235616493254474e-9\n  }\n}\n```\n\n## Examples\n\nA minimal usage example for Express + Mongoose can be found [here](./examples/express-mongoose/README.MD)\n\n## Contributing\n\nFeel free to provide feedback, open issues or create pull-requests to this repository.\n\n## License\n\nShortener is [MIT licensed](./LICENSE) by [Studio Hyperdrive](https://www.studiohyperdrive.be/).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstudiohyperdrive%2Fshortener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstudiohyperdrive%2Fshortener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstudiohyperdrive%2Fshortener/lists"}