scenv-zod 0.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.
- package/dist/index.cjs +38 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +13 -0
- package/package.json +41 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
validator: () => validator
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
function validator(schema) {
|
|
27
|
+
return (val) => {
|
|
28
|
+
const result = schema.safeParse(val);
|
|
29
|
+
if (result.success) {
|
|
30
|
+
return { success: true, data: result.data };
|
|
31
|
+
}
|
|
32
|
+
return { success: false, error: result.error };
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
validator
|
|
38
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a validator function for use with senv(), using a Zod schema.
|
|
5
|
+
* Values from env/context/--set are strings; the schema can coerce (e.g. z.coerce.number()).
|
|
6
|
+
*/
|
|
7
|
+
declare function validator<T extends z.ZodTypeAny>(schema: T): (val: unknown) => {
|
|
8
|
+
success: true;
|
|
9
|
+
data: z.infer<T>;
|
|
10
|
+
} | {
|
|
11
|
+
success: false;
|
|
12
|
+
error: unknown;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { validator };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a validator function for use with senv(), using a Zod schema.
|
|
5
|
+
* Values from env/context/--set are strings; the schema can coerce (e.g. z.coerce.number()).
|
|
6
|
+
*/
|
|
7
|
+
declare function validator<T extends z.ZodTypeAny>(schema: T): (val: unknown) => {
|
|
8
|
+
success: true;
|
|
9
|
+
data: z.infer<T>;
|
|
10
|
+
} | {
|
|
11
|
+
success: false;
|
|
12
|
+
error: unknown;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { validator };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function validator(schema) {
|
|
3
|
+
return (val) => {
|
|
4
|
+
const result = schema.safeParse(val);
|
|
5
|
+
if (result.success) {
|
|
6
|
+
return { success: true, data: result.data };
|
|
7
|
+
}
|
|
8
|
+
return { success: false, error: result.error };
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
validator
|
|
13
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "scenv-zod",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Zod validator for scenv variables",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/PKWadsy/senv.git"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"scenv",
|
|
11
|
+
"zod",
|
|
12
|
+
"validation"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "dist/index.cjs",
|
|
16
|
+
"module": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"zod": "^3.22.0",
|
|
30
|
+
"scenv": "0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"zod": "^3.22.0",
|
|
34
|
+
"tsup": "^8.0.0",
|
|
35
|
+
"typescript": "^5.3.0",
|
|
36
|
+
"scenv": "0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean"
|
|
40
|
+
}
|
|
41
|
+
}
|