Skip to content

Commit 79ec1d3

Browse files
committed
chore: wip
1 parent 8b9f12a commit 79ec1d3

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

.stacks/core/slug/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Stacks Database
2+
3+
wip
4+
5+
## ☘️ Features
6+
7+
wip
8+
9+
- ⚡️
10+
11+
wip
12+
13+
## 🤖 Usage
14+
15+
wip
16+
17+
```bash
18+
pnpm i -D @stacksjs/database
19+
```
20+
21+
Now, you can use it in your project:
22+
23+
```js
24+
import * as database from '@stacksjs/database'
25+
26+
// wip
27+
```
28+
29+
Learn more in the docs.
30+
31+
## 🧪 Testing
32+
33+
```bash
34+
pnpm test
35+
```
36+
37+
## 📈 Changelog
38+
39+
Please see our [releases](https://github.com/stacksjs/stacks/releases) page for more information on what has changed recently.
40+
41+
## 💪🏼 Contributing
42+
43+
Please review the [Contributing Guide](https://github.com/stacksjs/contributing) for details.
44+
45+
## 🏝 Community
46+
47+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
48+
49+
[Discussions on GitHub](https://github.com/stacksjs/stacks/discussions)
50+
51+
For casual chit-chat with others using this package:
52+
53+
[Join the Stacks Discord Server](https://discord.ow3.org)
54+
55+
## 📄 License
56+
57+
The MIT License (MIT). Please see [LICENSE](https://github.com/stacksjs/stacks/tree/main/LICENSE.md) for more information.
58+
59+
Made with ❤️

.stacks/core/slug/package.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "@stacksjs/database",
3+
"type": "module",
4+
"version": "0.51.0",
5+
"packageManager": "pnpm@7.28.0",
6+
"description": "The Stacks database integration.",
7+
"author": "Chris Breuer",
8+
"license": "MIT",
9+
"funding": "https://github.com/sponsors/chrisbbreuer",
10+
"homepage": "https://github.com/stacksjs/stacks/tree/main/.stacks/core/database#readme",
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/stacksjs/stacks.git",
14+
"directory": "./.stacks/core/database"
15+
},
16+
"bugs": {
17+
"url": "https://github.com/stacksjs/stacks/issues"
18+
},
19+
"keywords": [
20+
"database",
21+
"orm",
22+
"mysql",
23+
"postgres",
24+
"planetScale",
25+
"supabase",
26+
"singleStore",
27+
"prisma",
28+
"stacks"
29+
],
30+
"module": "dist/index.mjs",
31+
"types": "dist/index.d.ts",
32+
"contributors": [
33+
"Chris Breuer <chris@ow3.org>"
34+
],
35+
"files": [
36+
"dist",
37+
"README.md"
38+
],
39+
"engines": {
40+
"node": ">=v18.14.2",
41+
"pnpm": ">=7.28.0"
42+
},
43+
"scripts": {
44+
"build": "mkdist -d",
45+
"dev": "mkdist -d",
46+
"prepublishOnly": "pnpm run build",
47+
"typecheck": "tsc --noEmit"
48+
},
49+
"peerDependencies": {
50+
"@stacksjs/path": "workspace:*",
51+
"@stacksjs/utils": "workspace:*"
52+
},
53+
"devDependencies": {
54+
"@stacksjs/testing": "workspace:*",
55+
"mkdist": "^1.1.1",
56+
"typescript": "^4.9.5"
57+
},
58+
"dependencies": {
59+
"slugify": "^1.6.5"
60+
}
61+
}

.stacks/core/slug/src/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import slugify from 'slugify'
2+
import type { Model, ColumnOptions } from '@stacksjs/types'
3+
4+
export function generateSlug(model: Model, column: string, text: string): string {
5+
// Find the field that corresponds to the given column name
6+
const field: ColumnOptions | undefined = model.columns.find((f: ColumnOptions) => f.name === column)
7+
if (!field) {
8+
throw new Error(`Invalid column name: ${column}`)
9+
}
10+
11+
const fieldValue = text || ''
12+
const slug = slugify(fieldValue, { lower: true })
13+
14+
if (field.unique) {
15+
let uniqueSlug = slug
16+
let count = 0
17+
while (model.records.some((record) => record[column] === uniqueSlug)) {
18+
count++
19+
uniqueSlug = `${slug}-${count}`
20+
}
21+
return uniqueSlug
22+
}
23+
24+
return slug
25+
}
26+
27+
export {
28+
generateSlug as slug
29+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { assert, describe, test } from 'vitest'
2+
3+
describe('example test', () => {
4+
test('assert', () => {
5+
assert.equal(1, 1)
6+
})
7+
})

0 commit comments

Comments
 (0)