feat(core-shared): add slugField helper
This commit is contained in:
18
packages/core-shared/src/payload/fields/slug-field.test.ts
Normal file
18
packages/core-shared/src/payload/fields/slug-field.test.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { slugField } from "./slug-field";
|
||||||
|
|
||||||
|
describe("slugField", () => {
|
||||||
|
it("returns a Payload Field with default name 'slug'", () => {
|
||||||
|
const field = slugField();
|
||||||
|
expect(field.name).toBe("slug");
|
||||||
|
expect(field.type).toBe("text");
|
||||||
|
expect(field.required).toBe(true);
|
||||||
|
expect(field.unique).toBe(true);
|
||||||
|
expect(field.index).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("accepts a custom field name", () => {
|
||||||
|
const field = slugField("permalink");
|
||||||
|
expect(field.name).toBe("permalink");
|
||||||
|
});
|
||||||
|
});
|
||||||
11
packages/core-shared/src/payload/fields/slug-field.ts
Normal file
11
packages/core-shared/src/payload/fields/slug-field.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import type { Field } from "payload";
|
||||||
|
|
||||||
|
export function slugField(name = "slug"): Field {
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
type: "text",
|
||||||
|
required: true,
|
||||||
|
unique: true,
|
||||||
|
index: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user