{"id":21666787,"url":"https://github.com/tubbo/prisma-slug","last_synced_at":"2025-04-12T01:18:08.168Z","repository":{"id":57676828,"uuid":"489148262","full_name":"tubbo/prisma-slug","owner":"tubbo","description":"Prisma middleware that generates slugs for your models","archived":false,"fork":false,"pushed_at":"2023-12-15T11:49:09.000Z","size":96496,"stargazers_count":11,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T01:17:56.473Z","etag":null,"topics":["prisma","prisma-client"],"latest_commit_sha":null,"homepage":"https://tubbo.github.io/prisma-slug","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tubbo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2022-05-05T22:53:03.000Z","updated_at":"2024-09-03T09:48:05.000Z","dependencies_parsed_at":"2023-12-15T12:51:24.691Z","dependency_job_id":null,"html_url":"https://github.com/tubbo/prisma-slug","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"397a461686a43f7dc633bf960c4fc60552cdfff1"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tubbo%2Fprisma-slug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tubbo%2Fprisma-slug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tubbo%2Fprisma-slug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tubbo%2Fprisma-slug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tubbo","download_url":"https://codeload.github.com/tubbo/prisma-slug/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501856,"owners_count":21114684,"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":["prisma","prisma-client"],"created_at":"2024-11-25T11:29:22.134Z","updated_at":"2025-04-12T01:18:08.141Z","avatar_url":"https://github.com/tubbo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prisma-slug\n\nA slugification middleware for Prisma. It generates slugs for your\nmodels by using other model attributes with logic that you can define.\nIt's bundled with the excellent [slugify][] package and comes with\nreasonable defaults to let you define your Prisma schema without\nworrying about how you're going to generate URL-safe slugs.\n\n## Getting Started\n\nInstall the library:\n\n    yarn add prisma-slug\n\nThen, include it in the file you use to instantiate your Prisma client:\n\n```typescript\nimport { PrismaClient } from '@prisma/client'\nimport { PrismaSlug } from 'prisma-slug'\n\nconst db = new PrismaClient()\n\ndb.use(PrismaSlug())\n\nexport default db\n```\n\n## Usage\n\nThe `PrismaSlug()` function outputs a middleware that will convert model\nfields called `name` into a URL-safe slug and persist that to a field\ncalled `slug` on the same model. You can customize how this works by\npassing options into the function. For example, if you wanted to convert\n`title` fields as well as `name`, you'd configure the middleware like\nso:\n\n```typescript\ndb.use(\n  PrismaSlug({\n    source(params) {\n      return params.args.data.name ?? params.args.data.title\n    },\n  })\n)\n```\n\nYou can also configure the function used to generate the slug:\n\n```typescript\nimport slug from 'slug'\n\ndb.use(\n  PrismaSlug({\n    slugify: slug,\n  })\n)\n```\n\nBoth the `source()` and `slugify()` functions can return promises as\nwell.\n\nFor a full list of options, view the documentation at\nhttps://tubbo.github.io/prisma-slug/modules.html#PrismaSlugOptions.\n\n### Configuring Slugify Options\n\nTo configure [slugify][], define PrismaSlug's `slugify()` function and\npass in the options like so:\n\n```typescript\nimport slugify from 'slugify'\n\ndb.use(\n  PrismaSlug({\n    slugify(value) {\n      return slugify(value, {\n        /* ...your options... */\n      })\n    },\n  })\n)\n```\n\n### Unique Slugs\n\nCustomize the `slugify()` function to keep generating slugs until it\nfinds one that's unique:\n\n```typescript\nimport { camelCase } from 'camel-case'\nimport slugify from 'slugify'\n\ndb.use(\n  PrismaSlug({\n    async slugify(source, params) {\n      const method = camelCase(params.model)\n      const collection = db[method]\n      let slug = slugify(source)\n      let attempt = 0\n\n      while ((await collection.count({ where: { slug } })) \u003e 0) {\n        attempt += 1\n        slug = `${slug}-${attempt}`\n      }\n\n      return slug\n    },\n  })\n)\n```\n\n## Development\n\nThis project uses Yarn Plug'n'Play and Zero-Installs, meaning you don't\nneed to run `yarn install` to begin developing. However, depending on\nyour editor you may need to install an [editor SDK][].\n\nTo run tests:\n\n    yarn test\n\nTo run lint checks:\n\n    yarn lint\n\nTo run type checks:\n\n    yarn types\n\nYou can build the library by running:\n\n    yarn build\n\nAnd tear it down:\n\n    yarn clean\n\nUpon committing, your code will be automatically formatted and your\ncommit message checked to make sure it follows the [conventional\ncommits][] standard. All pull requests have tests, lint checks,\nformatting checks, type checks, and package security checks run against\nthem.\n\n[slugify]: https://www.npmjs.com/package/slugify\n[editor sdk]: https://yarnpkg.com/getting-started/editor-sdks\n[conventional commits]: https://www.conventionalcommits.org/en/v1.0.0/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftubbo%2Fprisma-slug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftubbo%2Fprisma-slug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftubbo%2Fprisma-slug/lists"}