@ptolemy2002/regex-utils 1.0.3 → 1.1.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.
Files changed (3) hide show
  1. package/README.md +20 -7
  2. package/index.js +3934 -10
  3. package/package.json +4 -2
package/README.md CHANGED
@@ -109,9 +109,23 @@ Checks if a string is a valid set of regular expression flags.
109
109
  #### Returns
110
110
  `Boolean` - `true` if the string is a valid set of regular expression flags, `false` otherwise.
111
111
 
112
+ ### zodValidate
113
+ #### Description
114
+ This is a simple function that takes a zod schema, returning a function that takes a value. If the value matches, the function returns `true`. Otherwise, it returns whatever error message the zod schema provides by default, or `false` if the `returnError` flag is disabled.
115
+
116
+ #### Parameters
117
+ - `p` (`ZodSchema`): The zod schema to be used for validation.
118
+ - `returnError` (`Boolean`): Whether to return the error message if the value does not match the schema. Default is `true`. If `false`, the function will return `false` on failure instead.
119
+
120
+ #### Returns
121
+ `Function` - A function that takes a value and returns `true` if the value matches the schema, an error message if the value does not match the schema and `returnError` is `true`, or `false` if the value does not match the schema and `returnError` is `false`.
122
+
123
+ #### Returns
124
+ `Function` - A function that takes a value and returns `true` if the value matches the schema, or an error message otherwise.
125
+
112
126
  ### isAlphanumeric
113
127
  #### Description
114
- Checks if a string is alphanumeric, that is, if it only contains letters, numbers, dashes, and underscores. Empty strings are not considered alphanumeric.
128
+ Uses `zodValidate` to check if a string is alphanumeric, that is, if it only contains letters, numbers, dashes, and underscores. Empty strings are not considered alphanumeric.
115
129
 
116
130
  #### Parameters
117
131
  - `str` (`String`): The value to be checked.
@@ -132,7 +146,7 @@ Transforms a string to be alphanumeric by removing accents, separating it by non
132
146
 
133
147
  ### isValidEmail
134
148
  #### Description
135
- Attempts to check if a string is a valid email address. Note that this is a simple check and may not cover all cases, but it should be good enough for most purposes.
149
+ Uses `zodValidate` to check if a string is a valid email address. Note that this is a simple check and may not cover all cases, but it should be good enough for most purposes.
136
150
 
137
151
  #### Parameters
138
152
  - `value` (`String`): The value to be checked.
@@ -142,7 +156,7 @@ Attempts to check if a string is a valid email address. Note that this is a simp
142
156
 
143
157
  ### isValidPhoneNumber
144
158
  #### Description
145
- Attempts to check if a string is a valid phone number. Note that this is a simple check and may not cover all cases, but it should be good enough for most purposes.
159
+ Uses `zodValidate` to check if a string is a valid phone number. Note that this is a simple check and may not cover all cases, but it should be good enough for most purposes.
146
160
 
147
161
  #### Parameters
148
162
  - `value` (`String`): The value to be checked.
@@ -152,7 +166,7 @@ Attempts to check if a string is a valid phone number. Note that this is a simpl
152
166
 
153
167
  ### isValidURL
154
168
  #### Description
155
- Attempts to check if a string is a valid URL. Note that this is a simple check and may not cover all cases, but it should be good enough for most purposes.
169
+ Uses `zodValidate` to check if a string is a valid URL. Note that this is a simple check and may not cover all cases, but it should be good enough for most purposes.
156
170
 
157
171
  #### Parameters
158
172
  - `value` (`String`): The value to be checked.
@@ -162,7 +176,7 @@ Attempts to check if a string is a valid URL. Note that this is a simple check a
162
176
 
163
177
  ### isValidSSN
164
178
  #### Description
165
- Attempts to check if a string is a valid Social Security Number (SSN). Note that this is a simple check and may not cover all cases, but it should be good enough for most purposes.
179
+ Uses `zodValidate` to check if a string is a valid Social Security Number (SSN). Note that this is a simple check and may not cover all cases, but it should be good enough for most purposes.
166
180
 
167
181
  #### Parameters
168
182
  - `value` (`String`): The value to be checked.
@@ -171,8 +185,7 @@ Attempts to check if a string is a valid Social Security Number (SSN). Note that
171
185
  `Boolean` - `true` if the string is a valid SSN, `false` otherwise.
172
186
 
173
187
  ## Meta
174
- This is a React Library Created by Ptolemy2002's [cra-template-react-library](https://www.npmjs.com/package/@ptolemy2002/cra-template-react-library) template in combination with [create-react-app](https://www.npmjs.com/package/create-react-app). It contains methods of building and publishing your library to npm.
175
- For now, the library makes use of React 18 and does not use TypeScript.
188
+ This is a React Library Created by Ptolemy2002's [cra-template-react-library](https://www.npmjs.com/package/@ptolemy2002/cra-template-react-library) template in combination with [create-react-app](https://www.npmjs.com/package/create-react-app). However, it does not actually depend on React - it has been modified to work out of the box. It contains methods of building and publishing your library to npm.
176
189
 
177
190
  ## Peer Dependencies
178
191
  This project does not have any peer dependencies, so it should work out of the box.