shelving 1.161.1 → 1.162.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.161.1",
14
+ "version": "1.162.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -3,11 +3,13 @@ import { Schema } from "./Schema.js";
3
3
  /** Allowed options for `BooleanSchema` */
4
4
  export interface BooleanSchemaOptions extends SchemaOptions {
5
5
  readonly value?: boolean | undefined;
6
+ readonly required?: boolean | undefined;
6
7
  }
7
8
  /** Define a valid boolean. */
8
9
  export declare class BooleanSchema extends Schema<boolean> {
9
10
  readonly value: boolean;
10
- constructor({ value, ...options }: BooleanSchemaOptions);
11
+ readonly required: boolean;
12
+ constructor({ value, required, ...options }: BooleanSchemaOptions);
11
13
  validate(unsafeValue?: unknown): boolean;
12
14
  }
13
15
  /** Valid boolean. */
@@ -1,14 +1,17 @@
1
+ import { Feedback } from "../feedback/Feedback.js";
1
2
  import { Schema } from "./Schema.js";
2
3
  const NEGATIVE = ["", "false", "0", "no", "n", "off"];
3
4
  /** Define a valid boolean. */
4
5
  export class BooleanSchema extends Schema {
5
- constructor({ value = false, ...options }) {
6
+ constructor({ value = false, required = false, ...options }) {
6
7
  super({ value, ...options });
8
+ this.required = required;
7
9
  }
8
10
  validate(unsafeValue = this.value) {
9
- if (typeof unsafeValue === "string")
10
- return !NEGATIVE.includes(unsafeValue.toLowerCase().trim());
11
- return !!unsafeValue;
11
+ const value = typeof unsafeValue === "string" ? !NEGATIVE.includes(unsafeValue.toLowerCase().trim()) : !!unsafeValue;
12
+ if (this.required)
13
+ throw new Feedback("Required");
14
+ return value;
12
15
  }
13
16
  }
14
17
  /** Valid boolean. */
package/util/url.js CHANGED
@@ -94,7 +94,7 @@ export function withURLParam(url, key, value, caller = withURLParam) {
94
94
  */
95
95
  export function withURLParams(url, params, caller = withURLParams) {
96
96
  const input = requireURL(url);
97
- const output = requireURL(url);
97
+ const output = new URL(input);
98
98
  for (const [key, str] of getURLEntries(params, caller))
99
99
  output.searchParams.set(key, str);
100
100
  return input.href === output.href ? input : output;
@@ -102,7 +102,7 @@ export function withURLParams(url, params, caller = withURLParams) {
102
102
  /** Return a URL without one or more params (or same URL if no changes were made). */
103
103
  export function omitURLParams(url, ...keys) {
104
104
  const input = requireURL(url);
105
- const output = requireURL(url);
105
+ const output = new URL(input);
106
106
  for (const key of keys)
107
107
  output.searchParams.delete(key);
108
108
  return input.href === output.href ? input : output;