@umatch/env-parser
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Validators = exports.Env = void 0; | ||
| const env_1 = require("./env"); | ||
| Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return env_1.Env; } }); | ||
| const BooleanValidator_1 = require("./Validators/BooleanValidator"); | ||
| const NumberValidator_1 = require("./Validators/NumberValidator"); | ||
| const StringValidator_1 = require("./Validators/StringValidator"); | ||
| class Validators { | ||
| static boolean() { | ||
| return new BooleanValidator_1.BooleanValidator(); | ||
| } | ||
| static number(options) { | ||
| return new NumberValidator_1.NumberValidator(options); | ||
| } | ||
| static port() { | ||
| return new NumberValidator_1.NumberValidator({ min: 1024, max: 65353 }); | ||
| } | ||
| static string(options) { | ||
| return new StringValidator_1.StringValidator(options); | ||
| } | ||
| } | ||
| exports.Validators = Validators; |
+44
| import type { Validator, Value } from './Validators'; | ||
| export class Env<Schema extends { [_: string]: Validator<Value> }> { | ||
| private readonly validated: { | ||
| readonly [K in keyof Schema]: Value; | ||
| }; | ||
| constructor(schema: Schema) { | ||
| this.validated = this.validate(schema); | ||
| } | ||
| private validate(schema: Schema): { [K in keyof Schema]: Value } { | ||
| const errors: string[] = []; | ||
| const validated = {} as { [K in keyof Schema]: Value }; | ||
| for (const key in schema) { | ||
| const validator = schema[key]; | ||
| try { | ||
| validated[key] = validator.validate(key); | ||
| } catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| const optional = validator._optional && message.match(/missing value/); | ||
| if (optional) { | ||
| if (validator._default !== undefined) { | ||
| validated[key] = validator._default; | ||
| } | ||
| } else { | ||
| errors.push(`${key}: ${message}`); | ||
| } | ||
| } | ||
| } | ||
| if (errors.length > 0) { | ||
| const sep = '\n\t- '; | ||
| throw new Error(`Error validating env vars:${sep}${errors.join(sep)}`); | ||
| } | ||
| return Object.freeze(validated); | ||
| } | ||
| public get<K extends keyof Schema>( | ||
| key: K, | ||
| ): Schema[K] extends Validator<infer T> ? T : never { | ||
| // @ts-expect-error generics | ||
| return this.validated[key]; | ||
| } | ||
| } |
+27
| import { Env } from './env'; | ||
| import { BooleanValidator } from './Validators/BooleanValidator'; | ||
| import { | ||
| NumberValidator, | ||
| type NumberValidationOptions, | ||
| } from './Validators/NumberValidator'; | ||
| import { | ||
| StringValidator, | ||
| type StringValidationOptions, | ||
| } from './Validators/StringValidator'; | ||
| class Validators { | ||
| static boolean() { | ||
| return new BooleanValidator(); | ||
| } | ||
| static number(options?: NumberValidationOptions) { | ||
| return new NumberValidator(options); | ||
| } | ||
| static port() { | ||
| return new NumberValidator({ min: 1024, max: 65353 }); | ||
| } | ||
| static string(options?: StringValidationOptions) { | ||
| return new StringValidator(options); | ||
| } | ||
| } | ||
| export { Env, Validators }; |
| import { parseBool } from '@umatch/utils/string'; | ||
| import { Validator } from './index'; | ||
| export class BooleanValidator extends Validator<boolean> { | ||
| protected _validate(raw: string): boolean { | ||
| return parseBool(raw); | ||
| } | ||
| } |
| import { isArray } from '@umatch/utils'; | ||
| import { deepMap } from '@umatch/utils/object'; | ||
| type ArrayValidationOptions = { | ||
| minLength?: number; | ||
| maxLength?: number; | ||
| }; | ||
| type NestedArray<T> = T | ReadonlyArray<NestedArray<T>>; | ||
| export type Value = NestedArray<string | number | boolean>; | ||
| function getRawEnv(key: string): string { | ||
| const raw = process.env[key]; | ||
| if (raw === undefined) { | ||
| throw new Error('missing value'); | ||
| } | ||
| return raw; | ||
| } | ||
| export abstract class Validator<T extends Value> { | ||
| private _arrayOptions?: ArrayValidationOptions; | ||
| public _default?: Value; | ||
| public _optional = false; | ||
| protected abstract _validate(raw: string): T; | ||
| public validate(key: string): Value { | ||
| const raw = getRawEnv(key); | ||
| if (!this._arrayOptions) { | ||
| return this._validate(raw); | ||
| } | ||
| // this is an array validator - validate the array, then each value | ||
| const parsed = JSON.parse(raw.replace(/'/g, '"')) as unknown; | ||
| if (!isArray(parsed)) { | ||
| throw new Error('not an array'); | ||
| } | ||
| const opts = { minLength: 1, ...this._arrayOptions }; | ||
| if (opts.minLength > parsed.length) { | ||
| throw new Error('array too short'); | ||
| } | ||
| if (opts.maxLength && opts.maxLength < parsed.length) { | ||
| throw new Error('array too long'); | ||
| } | ||
| // @ts-expect-error generics | ||
| return deepMap(parsed, this._validate.bind(this)); | ||
| } | ||
| public array(opts: ArrayValidationOptions = {}): Validator<T[]> { | ||
| this._arrayOptions = opts; | ||
| return this as unknown as Validator<T[]>; | ||
| } | ||
| public optional(defaultValue?: T) { | ||
| this._default = defaultValue; | ||
| this._optional = true; | ||
| return this; | ||
| } | ||
| } |
| import { Validator } from './index'; | ||
| export type NumberValidationOptions = { min?: number; max?: number }; | ||
| export class NumberValidator extends Validator<number> { | ||
| private readonly min?: number; | ||
| private readonly max?: number; | ||
| public constructor(opts?: NumberValidationOptions) { | ||
| super(); | ||
| this.min = opts?.min; | ||
| this.max = opts?.max; | ||
| } | ||
| protected _validate(raw: string) { | ||
| const val = Number(raw); | ||
| if (isNaN(val)) { | ||
| throw new Error('not a number'); | ||
| } | ||
| if (this.min && val < this.min) { | ||
| throw new Error('too small'); | ||
| } | ||
| if (this.max && val > this.max) { | ||
| throw new Error('too large'); | ||
| } | ||
| return val; | ||
| } | ||
| } |
| import { Validator } from './index'; | ||
| export type StringValidationOptions = { | ||
| minLength?: number; | ||
| maxLength?: number; | ||
| }; | ||
| export class StringValidator extends Validator<string> { | ||
| private readonly minLength?: number; | ||
| private readonly maxLength?: number; | ||
| public constructor(opts?: StringValidationOptions) { | ||
| super(); | ||
| this.minLength = opts?.minLength; | ||
| this.maxLength = opts?.maxLength; | ||
| } | ||
| protected _validate(raw: string): string { | ||
| const val = String(raw); | ||
| if (this.minLength && val.length < this.minLength) { | ||
| throw new Error('too short'); | ||
| } | ||
| if (this.maxLength && val.length > this.maxLength) { | ||
| throw new Error('too long'); | ||
| } | ||
| return val; | ||
| } | ||
| } |
+4
-4
@@ -1,6 +0,5 @@ | ||
| import type Validator from './Validators'; | ||
| export default class Env<Schema extends { | ||
| [_: string]: Validator<unknown>; | ||
| import type { Validator, Value } from './Validators'; | ||
| export declare class Env<Schema extends { | ||
| [_: string]: Validator<Value>; | ||
| }> { | ||
| private readonly schema; | ||
| private readonly validated; | ||
@@ -11,1 +10,2 @@ constructor(schema: Schema); | ||
| } | ||
| //# sourceMappingURL=env.d.ts.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,GAAG,CAAC,MAAM,SAAS;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;CAAE;IACzE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAExB;gBAEU,MAAM,EAAE,MAAM;IAO1B,OAAO,CAAC,QAAQ;IA0BT,GAAG,CAAC,CAAC,SAAS,MAAM,MAAM,EAC/B,GAAG,EAAE,CAAC,GACL,MAAM,CAAC,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAGpD"} | ||
| {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErD,qBAAa,GAAG,CAAC,MAAM,SAAS;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;CAAE;IAC/D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAExB;gBAEU,MAAM,EAAE,MAAM;IAI1B,OAAO,CAAC,QAAQ;IA0BT,GAAG,CAAC,CAAC,SAAS,MAAM,MAAM,EAC/B,GAAG,EAAE,CAAC,GACL,MAAM,CAAC,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAIpD"} |
+12
-11
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Env = void 0; | ||
| class Env { | ||
| constructor(schema) { | ||
| this.schema = schema; | ||
| // @ts-ignore | ||
| this.validated = {}; | ||
| this.validate(); | ||
| this.validated = this.validate(schema); | ||
| } | ||
| validate() { | ||
| validate(schema) { | ||
| const errors = []; | ||
| Object.entries(this.schema).forEach(([key, validator]) => { | ||
| const validated = {}; | ||
| for (const key in schema) { | ||
| const validator = schema[key]; | ||
| try { | ||
| this.validated[key] = validator.validate(key); | ||
| validated[key] = validator.validate(key); | ||
| } | ||
@@ -21,3 +21,3 @@ catch (error) { | ||
| if (validator._default !== undefined) { | ||
| this.validated[key] = validator._default; | ||
| validated[key] = validator._default; | ||
| } | ||
@@ -29,3 +29,3 @@ } | ||
| } | ||
| }); | ||
| } | ||
| if (errors.length > 0) { | ||
@@ -35,8 +35,9 @@ const sep = '\n\t- '; | ||
| } | ||
| Object.freeze(this.validated); | ||
| return Object.freeze(validated); | ||
| } | ||
| get(key) { | ||
| // @ts-expect-error generics | ||
| return this.validated[key]; | ||
| } | ||
| } | ||
| exports.default = Env; | ||
| exports.Env = Env; |
+5
-4
@@ -0,6 +1,6 @@ | ||
| import { Env } from './env'; | ||
| import { BooleanValidator } from './Validators/BooleanValidator'; | ||
| import { NumberValidator, NumberValidationOptions } from './Validators/NumberValidator'; | ||
| import { StringValidator, StringValidationOptions } from './Validators/StringValidator'; | ||
| export { default as Env } from './env'; | ||
| export declare class Validators { | ||
| import { NumberValidator, type NumberValidationOptions } from './Validators/NumberValidator'; | ||
| import { StringValidator, type StringValidationOptions } from './Validators/StringValidator'; | ||
| declare class Validators { | ||
| static boolean(): BooleanValidator; | ||
@@ -11,2 +11,3 @@ static number(options?: NumberValidationOptions): NumberValidator; | ||
| } | ||
| export { Env, Validators }; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAExF,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC;AACvC,qBAAa,UAAU;IACrB,MAAM,CAAC,OAAO;IAGd,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,uBAAuB;IAG/C,MAAM,CAAC,IAAI;IAGX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,uBAAuB;CAGhD"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EACL,eAAe,EACf,KAAK,uBAAuB,EAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,eAAe,EACf,KAAK,uBAAuB,EAC7B,MAAM,8BAA8B,CAAC;AAEtC,cAAM,UAAU;IACd,MAAM,CAAC,OAAO;IAGd,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,uBAAuB;IAG/C,MAAM,CAAC,IAAI;IAGX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,uBAAuB;CAGhD;AAED,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC"} |
+2
-5
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Validators = exports.Env = void 0; | ||
| const env_1 = require("./env"); | ||
| Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return env_1.Env; } }); | ||
| const BooleanValidator_1 = require("./Validators/BooleanValidator"); | ||
| const NumberValidator_1 = require("./Validators/NumberValidator"); | ||
| const StringValidator_1 = require("./Validators/StringValidator"); | ||
| var env_1 = require("./env"); | ||
| Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return __importDefault(env_1).default; } }); | ||
| class Validators { | ||
@@ -13,0 +10,0 @@ static boolean() { |
@@ -1,4 +0,5 @@ | ||
| import Validator from './index'; | ||
| import { Validator } from './index'; | ||
| export declare class BooleanValidator extends Validator<boolean> { | ||
| protected _validate(raw: string): boolean; | ||
| } | ||
| //# sourceMappingURL=BooleanValidator.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"BooleanValidator.d.ts","sourceRoot":"","sources":["../../src/Validators/BooleanValidator.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,SAAS,CAAC;AAEhC,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,OAAO,CAAC;IACtD,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAG1C"} | ||
| {"version":3,"file":"BooleanValidator.d.ts","sourceRoot":"","sources":["../../src/Validators/BooleanValidator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,qBAAa,gBAAiB,SAAQ,SAAS,CAAC,OAAO,CAAC;IACtD,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;CAG1C"} |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.BooleanValidator = void 0; | ||
| const string_1 = require("@umatch/utils/string"); | ||
| const index_1 = __importDefault(require("./index")); | ||
| class BooleanValidator extends index_1.default { | ||
| const index_1 = require("./index"); | ||
| class BooleanValidator extends index_1.Validator { | ||
| _validate(raw) { | ||
@@ -11,0 +8,0 @@ return (0, string_1.parseBool)(raw); |
@@ -1,11 +0,13 @@ | ||
| declare type ArrayValidationOptions = { | ||
| type ArrayValidationOptions = { | ||
| minLength?: number; | ||
| maxLength?: number; | ||
| }; | ||
| export default abstract class Validator<T> { | ||
| type NestedArray<T> = T | ReadonlyArray<NestedArray<T>>; | ||
| export type Value = NestedArray<string | number | boolean>; | ||
| export declare abstract class Validator<T extends Value> { | ||
| private _arrayOptions?; | ||
| _default?: T; | ||
| _default?: Value; | ||
| _optional: boolean; | ||
| protected abstract _validate(raw: string): T; | ||
| validate(key: string): any; | ||
| validate(key: string): Value; | ||
| array(opts?: ArrayValidationOptions): Validator<T[]>; | ||
@@ -15,1 +17,2 @@ optional(defaultValue?: T): this; | ||
| export {}; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Validators/index.ts"],"names":[],"mappings":"AAEA,aAAK,sBAAsB,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAUF,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,SAAS,CAAC,CAAC;IACvC,OAAO,CAAC,aAAa,CAAC,CAAyB;IACxC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACb,SAAS,UAAS;IAEzB,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC;IAErC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG;IAyB1B,KAAK,CAAC,IAAI,GAAE,sBAA2B,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC;IAKxD,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;CAKjC"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Validators/index.ts"],"names":[],"mappings":"AAGA,KAAK,sBAAsB,GAAG;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,MAAM,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;AAU3D,8BAAsB,SAAS,CAAC,CAAC,SAAS,KAAK;IAC7C,OAAO,CAAC,aAAa,CAAC,CAAyB;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC;IACjB,SAAS,UAAS;IAEzB,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC;IAErC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IA0B5B,KAAK,CAAC,IAAI,GAAE,sBAA2B,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC;IAKxD,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;CAKjC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Validator = void 0; | ||
| const utils_1 = require("@umatch/utils"); | ||
| const object_1 = require("@umatch/utils/object"); | ||
@@ -22,3 +24,3 @@ function getRawEnv(key) { | ||
| const parsed = JSON.parse(raw.replace(/'/g, '"')); | ||
| if (!Array.isArray(parsed)) { | ||
| if (!(0, utils_1.isArray)(parsed)) { | ||
| throw new Error('not an array'); | ||
@@ -33,2 +35,3 @@ } | ||
| } | ||
| // @ts-expect-error generics | ||
| return (0, object_1.deepMap)(parsed, this._validate.bind(this)); | ||
@@ -46,2 +49,2 @@ } | ||
| } | ||
| exports.default = Validator; | ||
| exports.Validator = Validator; |
@@ -1,11 +0,12 @@ | ||
| import Validator from './index'; | ||
| export declare type NumberValidationOptions = { | ||
| import { Validator } from './index'; | ||
| export type NumberValidationOptions = { | ||
| min?: number; | ||
| max?: number; | ||
| }; | ||
| export interface NumberValidator extends NumberValidationOptions { | ||
| } | ||
| export declare class NumberValidator extends Validator<number> { | ||
| private readonly min?; | ||
| private readonly max?; | ||
| constructor(opts?: NumberValidationOptions); | ||
| protected _validate(raw: string): number; | ||
| } | ||
| //# sourceMappingURL=NumberValidator.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"NumberValidator.d.ts","sourceRoot":"","sources":["../../src/Validators/NumberValidator.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,SAAS,CAAC;AAQhC,oBAAY,uBAAuB,GAAG;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AACF,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;CAAG;AACnE,qBAAa,eAAgB,SAAQ,SAAS,CAAC,MAAM,CAAC;gBACjC,IAAI,CAAC,EAAE,uBAAuB;IAKjD,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAiBzC"} | ||
| {"version":3,"file":"NumberValidator.d.ts","sourceRoot":"","sources":["../../src/Validators/NumberValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,MAAM,MAAM,uBAAuB,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE,qBAAa,eAAgB,SAAQ,SAAS,CAAC,MAAM,CAAC;IACpD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAS;gBACX,IAAI,CAAC,EAAE,uBAAuB;IAMjD,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM;CAiBhC"} |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.NumberValidator = void 0; | ||
| const index_1 = __importDefault(require("./index")); | ||
| class NumberValidator extends index_1.default { | ||
| const index_1 = require("./index"); | ||
| class NumberValidator extends index_1.Validator { | ||
| constructor(opts) { | ||
| super(); | ||
| Object.assign(this, opts); | ||
| this.min = opts?.min; | ||
| this.max = opts?.max; | ||
| } | ||
@@ -13,0 +11,0 @@ _validate(raw) { |
@@ -1,11 +0,12 @@ | ||
| import Validator from './index'; | ||
| export declare type StringValidationOptions = { | ||
| import { Validator } from './index'; | ||
| export type StringValidationOptions = { | ||
| minLength?: number; | ||
| maxLength?: number; | ||
| }; | ||
| export interface StringValidator extends StringValidationOptions { | ||
| } | ||
| export declare class StringValidator extends Validator<string> { | ||
| private readonly minLength?; | ||
| private readonly maxLength?; | ||
| constructor(opts?: StringValidationOptions); | ||
| protected _validate(raw: string): string; | ||
| } | ||
| //# sourceMappingURL=StringValidator.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"StringValidator.d.ts","sourceRoot":"","sources":["../../src/Validators/StringValidator.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,SAAS,CAAC;AAQhC,oBAAY,uBAAuB,GAAG;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;CAAG;AACnE,qBAAa,eAAgB,SAAQ,SAAS,CAAC,MAAM,CAAC;gBACjC,IAAI,CAAC,EAAE,uBAAuB;IAKjD,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAazC"} | ||
| {"version":3,"file":"StringValidator.d.ts","sourceRoot":"","sources":["../../src/Validators/StringValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AACF,qBAAa,eAAgB,SAAQ,SAAS,CAAC,MAAM,CAAC;IACpD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAS;gBAEjB,IAAI,CAAC,EAAE,uBAAuB;IAMjD,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAazC"} |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.StringValidator = void 0; | ||
| const index_1 = __importDefault(require("./index")); | ||
| class StringValidator extends index_1.default { | ||
| const index_1 = require("./index"); | ||
| class StringValidator extends index_1.Validator { | ||
| constructor(opts) { | ||
| super(); | ||
| Object.assign(this, opts); | ||
| this.minLength = opts?.minLength; | ||
| this.maxLength = opts?.maxLength; | ||
| } | ||
@@ -13,0 +11,0 @@ _validate(raw) { |
+24
-20
| { | ||
| "name": "@umatch/env-parser", | ||
| "version": "0.1.0", | ||
| "version": "1.0.0", | ||
| "description": "Parse and validate environment variables, with TypeScript support", | ||
@@ -12,3 +12,4 @@ "author": "Gabriel Okamoto <gabrielokamoto@hotmail.com>", | ||
| "files": [ | ||
| "lib/**/*.d.ts", | ||
| "src/**/*.ts", | ||
| "lib/**/*.ts", | ||
| "lib/**/*.ts.map", | ||
@@ -18,19 +19,21 @@ "lib/**/*.js" | ||
| "devDependencies": { | ||
| "@types/jest": "^29.2.0", | ||
| "@types/node": "^18.11.7", | ||
| "@typescript-eslint/eslint-plugin": "^5.40.1", | ||
| "@typescript-eslint/parser": "^5.40.1", | ||
| "eslint": "~8.22.0", | ||
| "eslint-config-prettier": "^8.5.0", | ||
| "eslint-import-resolver-typescript": "^3.5.1", | ||
| "eslint-plugin-import": "^2.26.0", | ||
| "eslint-plugin-prettier": "^4.2.1", | ||
| "jest": "^29.2.2", | ||
| "prettier": "^2.7.1", | ||
| "ts-jest": "^29.0.3", | ||
| "ts-node": "^10.9.1", | ||
| "typescript": "^4.8.4" | ||
| "@types/jest": "^29.5.11", | ||
| "@types/luxon": "^3.3.7", | ||
| "@types/node": "^20.10.4", | ||
| "@typescript-eslint/eslint-plugin": "^6.14.0", | ||
| "@typescript-eslint/parser": "^6.14.0", | ||
| "@umatch/eslint-config": "^1.4.1", | ||
| "commit-and-tag-version": "^12.0.0", | ||
| "eslint": "^8.55.0", | ||
| "eslint-config-prettier": "^9.1.0", | ||
| "eslint-import-resolver-typescript": "^3.6.1", | ||
| "eslint-plugin-import": "^2.29.0", | ||
| "jest": "^29.7.0", | ||
| "prettier": "~3.0.3", | ||
| "ts-jest": "^29.1.1", | ||
| "ts-node": "^10.9.2", | ||
| "typescript": "^5.3.3" | ||
| }, | ||
| "dependencies": { | ||
| "@umatch/utils": "^1.10.0" | ||
| "@umatch/utils": "^12.4.0" | ||
| }, | ||
@@ -40,6 +43,7 @@ "scripts": { | ||
| "test": "jest", | ||
| "lint": "eslint . --ext .ts", | ||
| "preversion": "npm run lint", | ||
| "postversion": "git push && git push --tags" | ||
| "lint": "eslint . --ext=.ts", | ||
| "format": "prettier --check --log-level warn --cache --cache-strategy metadata --config ./.prettierrc.js .", | ||
| "push-publish": "git push --follow-tags && pnpm publish --ignore-scripts", | ||
| "release": "pnpm prepublishOnly && pnpm commit-and-tag-version -a" | ||
| } | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
18552
52.37%27
35%423
80.77%0
-100%16
14.29%3
50%1
Infinity%+ Added
- Removed
Updated