yuppi 1.3.0 → 1.3.2

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
@@ -224,9 +224,9 @@ Declare your Yuppi schema for TypeScript.
224
224
  > Example:
225
225
  >
226
226
  > ```typescript
227
- > import type { User } from './yuppi/types/user';
227
+ > import type { User } from './yuppi/types/User';
228
228
  >
229
- > Yupp.declare(schema, 'user');
229
+ > Yupp.declare(schema, 'User');
230
230
  >
231
231
  > const user = Yupp.validate(schema, properties) as User;
232
232
  > /*
package/dist/main.js CHANGED
@@ -45,8 +45,8 @@ var import_path = __toESM(require("path"));
45
45
  var import_typebox = require("@sinclair/typebox");
46
46
  var convertToJSONSchema = (schema) => {
47
47
  const base = (schema2, key, config) => {
48
- if (!config.required) schema2 = import_typebox.Type.Optional(schema2);
49
48
  if (config.nullable || config.default === null) schema2 = import_typebox.Type.Union([schema2, import_typebox.Type.Null()]);
49
+ if (!config.required) schema2 = import_typebox.Type.Optional(schema2);
50
50
  return schema2;
51
51
  };
52
52
  const build = (key, config) => {
@@ -89,6 +89,8 @@ var Yup = __toESM(require("yup"));
89
89
  var convertToYup = (schema, error_messages) => {
90
90
  const base = (schema2, key, config) => {
91
91
  schema2 = schema2.nullable();
92
+ if (config.default) schema2 = schema2.default(config.default);
93
+ if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
92
94
  if (config.required)
93
95
  schema2 = schema2.test(
94
96
  "required",
@@ -100,8 +102,6 @@ var convertToYup = (schema, error_messages) => {
100
102
  return true;
101
103
  }
102
104
  );
103
- if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
104
- if (config.default) schema2 = schema2.default(config.default);
105
105
  return schema2;
106
106
  };
107
107
  const build = (key, config) => {
@@ -178,6 +178,11 @@ var convertToYup = (schema, error_messages) => {
178
178
  return Yup.object().shape(properties);
179
179
  };
180
180
 
181
+ // src/utils/PascalCase.util.ts
182
+ var pascalCase = (text) => {
183
+ return text.replace(/[^a-zA-Z0-9]/g, " ").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
184
+ };
185
+
181
186
  // src/defaults/YuppiOptions.default.ts
182
187
  var YuppiOptionsDefault = {
183
188
  folder_path: "./",
@@ -236,7 +241,7 @@ var Yuppi = class {
236
241
  return yup_schema.validateSync(properties, this.options.validate_options);
237
242
  }
238
243
  declare(schema, name) {
239
- name = name.toLowerCase();
244
+ name = pascalCase(name);
240
245
  const types_dir = import_path.default.join(this.options.folder_path ?? "./", "yuppi", "types");
241
246
  const banner_comment = `/* eslint-disable */
242
247
 
package/dist/main.mjs CHANGED
@@ -14,8 +14,8 @@ import path from "path";
14
14
  import { Type } from "@sinclair/typebox";
15
15
  var convertToJSONSchema = (schema) => {
16
16
  const base = (schema2, key, config) => {
17
- if (!config.required) schema2 = Type.Optional(schema2);
18
17
  if (config.nullable || config.default === null) schema2 = Type.Union([schema2, Type.Null()]);
18
+ if (!config.required) schema2 = Type.Optional(schema2);
19
19
  return schema2;
20
20
  };
21
21
  const build = (key, config) => {
@@ -58,6 +58,8 @@ import * as Yup from "yup";
58
58
  var convertToYup = (schema, error_messages) => {
59
59
  const base = (schema2, key, config) => {
60
60
  schema2 = schema2.nullable();
61
+ if (config.default) schema2 = schema2.default(config.default);
62
+ if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
61
63
  if (config.required)
62
64
  schema2 = schema2.test(
63
65
  "required",
@@ -69,8 +71,6 @@ var convertToYup = (schema, error_messages) => {
69
71
  return true;
70
72
  }
71
73
  );
72
- if (!config.nullable && config.default !== null) schema2 = schema2.nonNullable(({ path: path2 }) => (error_messages?.base?.nullable ?? "").replaceAll("{path}", path2));
73
- if (config.default) schema2 = schema2.default(config.default);
74
74
  return schema2;
75
75
  };
76
76
  const build = (key, config) => {
@@ -147,6 +147,11 @@ var convertToYup = (schema, error_messages) => {
147
147
  return Yup.object().shape(properties);
148
148
  };
149
149
 
150
+ // src/utils/PascalCase.util.ts
151
+ var pascalCase = (text) => {
152
+ return text.replace(/[^a-zA-Z0-9]/g, " ").split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
153
+ };
154
+
150
155
  // src/defaults/YuppiOptions.default.ts
151
156
  var YuppiOptionsDefault = {
152
157
  folder_path: "./",
@@ -205,7 +210,7 @@ var Yuppi = class {
205
210
  return yup_schema.validateSync(properties, this.options.validate_options);
206
211
  }
207
212
  declare(schema, name) {
208
- name = name.toLowerCase();
213
+ name = pascalCase(name);
209
214
  const types_dir = path.join(this.options.folder_path ?? "./", "yuppi", "types");
210
215
  const banner_comment = `/* eslint-disable */
211
216
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuppi",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Schemas that can be converted to Yup and JSON Schema.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/keift/yuppi",