shelving 1.20.3 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.20.3",
14
+ "version": "1.21.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -0,0 +1,18 @@
1
+ import { StringSchema } from "./StringSchema.js";
2
+ /**
3
+ * Define a valid slug, e.g. `this-is-a-slug`
4
+ *
5
+ * - Useful for URL components, usernames, etc.
6
+ * - Minimum slug length is 2 characters.
7
+ * - Maximum slug length is 64 characters.
8
+ */
9
+ export declare class SlugSchema extends StringSchema {
10
+ readonly multiline = false;
11
+ readonly min = 2;
12
+ readonly max = 32;
13
+ sanitize(unsafeString: string): string;
14
+ }
15
+ /** Valid slug, e.g. `this-is-a-slug` */
16
+ export declare const SLUG: SlugSchema;
17
+ /** Valid slug, e.g. `this-is-a-slug`, or `null` */
18
+ export declare const OPTIONAL_SLUG: import("./OptionalSchema.js").OptionalSchema<string>;
@@ -0,0 +1,25 @@
1
+ import { toSlug } from "../util/index.js";
2
+ import { OPTIONAL } from "./OptionalSchema.js";
3
+ import { StringSchema } from "./StringSchema.js";
4
+ /**
5
+ * Define a valid slug, e.g. `this-is-a-slug`
6
+ *
7
+ * - Useful for URL components, usernames, etc.
8
+ * - Minimum slug length is 2 characters.
9
+ * - Maximum slug length is 64 characters.
10
+ */
11
+ export class SlugSchema extends StringSchema {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.multiline = false;
15
+ this.min = 2;
16
+ this.max = 32;
17
+ }
18
+ sanitize(unsafeString) {
19
+ return toSlug(unsafeString);
20
+ }
21
+ }
22
+ /** Valid slug, e.g. `this-is-a-slug` */
23
+ export const SLUG = new SlugSchema({});
24
+ /** Valid slug, e.g. `this-is-a-slug`, or `null` */
25
+ export const OPTIONAL_SLUG = OPTIONAL(SLUG);
package/schema/index.d.ts CHANGED
@@ -7,12 +7,13 @@ export * from "./DataSchema.js";
7
7
  export * from "./DateSchema.js";
8
8
  export * from "./EmailSchema.js";
9
9
  export * from "./KeySchema.js";
10
+ export * from "./LinkSchema.js";
10
11
  export * from "./MapSchema.js";
11
- export * from "./OptionalSchema.js";
12
12
  export * from "./NumberSchema.js";
13
13
  export * from "./ObjectSchema.js";
14
+ export * from "./OptionalSchema.js";
14
15
  export * from "./PhoneSchema.js";
15
16
  export * from "./RequiredSchema.js";
17
+ export * from "./SlugSchema.js";
16
18
  export * from "./StringSchema.js";
17
19
  export * from "./ThroughSchema.js";
18
- export * from "./LinkSchema.js";
package/schema/index.js CHANGED
@@ -7,12 +7,13 @@ export * from "./DataSchema.js";
7
7
  export * from "./DateSchema.js";
8
8
  export * from "./EmailSchema.js";
9
9
  export * from "./KeySchema.js";
10
+ export * from "./LinkSchema.js";
10
11
  export * from "./MapSchema.js";
11
- export * from "./OptionalSchema.js";
12
12
  export * from "./NumberSchema.js";
13
13
  export * from "./ObjectSchema.js";
14
+ export * from "./OptionalSchema.js";
14
15
  export * from "./PhoneSchema.js";
15
16
  export * from "./RequiredSchema.js";
17
+ export * from "./SlugSchema.js";
16
18
  export * from "./StringSchema.js";
17
19
  export * from "./ThroughSchema.js";
18
- export * from "./LinkSchema.js";