@ptolemy2002/regex-utils 2.1.0 → 2.2.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/README.md CHANGED
@@ -216,6 +216,15 @@ Uses `zodValidate` to check if a string is a valid Social Security Number (SSN).
216
216
  #### Returns
217
217
  `boolean` - `true` if the string is a valid SSN, `false` otherwise.
218
218
 
219
+ ## Schemas
220
+ The following schemas are available in the library:
221
+
222
+ ### ZodCoercedBooleanEnum
223
+ A zod schema that specifies an enum of strings that can be interpreted as booleans. This is used within `ZodCoercedBoolean` to actually perform the coercion.
224
+
225
+ ### ZodCoercedBoolean
226
+ A zod schema that takes in a value accepted by `ZodCoercedBooleanEnum` and coerces it to a boolean. This is useful when you want to accept multiple values that can be interpreted as booleans.
227
+
219
228
  ## Peer Dependencies
220
229
  These should be installed in order to use the library, as npm does not automatically add peer dependencies to your project.
221
230
  - zod: ^3.23.8
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ZodError, ZodSchema } from "zod";
1
+ import { z, ZodError, ZodSchema } from "zod";
2
2
  export type RegexInput = string | RegExp;
3
3
  export declare function combineFlags(...flags: string[]): string;
4
4
  export declare function escapeRegex(value: RegexInput, flags?: string): RegExp;
@@ -26,3 +26,5 @@ export declare function isValidEmail(v: string): boolean;
26
26
  export declare function isValidURL(v: string): boolean;
27
27
  export declare function isValidPhoneNumber(v: string): boolean;
28
28
  export declare function isValidSSN(v: string): boolean;
29
+ export declare const ZodCoercedBooleanEnum: z.ZodEnum<["true", "false", "t", "f", "yes", "no", "y", "n", "1", "0", "on", "off"]>;
30
+ export declare const ZodCoercedBoolean: z.ZodEffects<z.ZodEnum<["true", "false", "t", "f", "yes", "no", "y", "n", "1", "0", "on", "off"]>, boolean, "0" | "1" | "true" | "false" | "t" | "f" | "yes" | "no" | "y" | "n" | "on" | "off">;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZodCoercedBoolean = exports.ZodCoercedBooleanEnum = void 0;
3
4
  exports.combineFlags = combineFlags;
4
5
  exports.escapeRegex = escapeRegex;
5
6
  exports.regexAccentInsensitive = regexAccentInsensitive;
@@ -157,3 +158,29 @@ function isValidPhoneNumber(v) {
157
158
  function isValidSSN(v) {
158
159
  return zodValidate(zod_1.z.coerce.string().regex(/^\d{3}-?\d{2}-?\d{4}$/))(v);
159
160
  }
161
+ exports.ZodCoercedBooleanEnum = zod_1.z.enum([
162
+ "true", "false",
163
+ "t", "f",
164
+ "yes", "no",
165
+ "y", "n",
166
+ "1", "0",
167
+ "on", "off"
168
+ ]);
169
+ exports.ZodCoercedBoolean = exports.ZodCoercedBooleanEnum.transform((val) => {
170
+ switch (val) {
171
+ case "true":
172
+ case "t":
173
+ case "yes":
174
+ case "y":
175
+ case "1":
176
+ case "on":
177
+ return true;
178
+ case "false":
179
+ case "f":
180
+ case "no":
181
+ case "n":
182
+ case "0":
183
+ case "off":
184
+ return false;
185
+ }
186
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/regex-utils",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",