About
@nanoforge-dev/env is a wrapper around class-validator and class-transformer used to validate and transform raw environment values (InitContext.env, process.env, …) into typed, decorated configuration classes.
Installation
Node.js 26 or newer is required.Warning
This library is intended for use by other NanoForge libraries and application code that reads environment configuration — it is not a library that consumers of@nanoforge-dev/core need to install standalone unless they are declaring their own environment-backed config classes.
Example usage
Declare a configuration class decorated with@nanoforge-dev/env’s decorators:
registerEnv:
registerEnv throws NfEnvValidationException when the given environment doesn’t satisfy the class’s decorators.
All of class-validator’s decorators (IsString, IsPort, IsOptional, …) and class-transformer’s @Expose/@Transform are re-exported directly from this package, alongside @nanoforge-dev/env’s own additions:
@Default(value)— supplies a fallback when the property isundefined/null.@IsIpOrURL(...)— validates an IPv4/IPv6 address or a fully qualified domain name.@TransformToBoolean()— transforms the string"true"/"false"into a native boolean.
Links
Contributing
Before creating an issue, please ensure that it hasn’t already been reported/suggested, and double-check the documentation.See the contribution guide if you’d like to submit a PR.
Help
If you don’t understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don’t hesitate to ask questions in discussions.Classes
Functions
- Allow
- ArrayContains
- ArrayMaxSize
- ArrayMinSize
- ArrayNotContains
- ArrayNotEmpty
- ArrayUnique
- Contains
- Default
- Equals
- Expose
- IsAlpha
- IsAlphanumeric
- IsArray
- IsAscii
- IsBase32
- IsBase58
- IsBase64
- IsBIC
- IsBoolean
- IsBooleanString
- IsBtcAddress
- IsByteLength
- IsCreditCard
- IsCurrency
- IsDataURI
- IsDate
- IsDateString
- IsDecimal
- IsDefined
- IsDivisibleBy
- IsEAN
- IsEmail
- IsEmpty
- IsEnum
- IsEthereumAddress
- IsFirebasePushId
- IsFQDN
- IsFullWidth
- IsHalfWidth
- IsHash
- IsHexadecimal
- IsHexColor
- IsHSL
- IsIBAN
- IsIdentityCard
- IsIn
- IsInstance
- IsInt
- IsIP
- IsIpOrURL
- IsISBN
- IsISIN
- IsISO31661Alpha2
- IsISO31661Alpha3
- IsISO4217CurrencyCode
- IsISO8601
- IsISRC
- IsISSN
- IsJSON
- IsJWT
- IsLatitude
- IsLatLong
- IsLocale
- IsLongitude
- IsLowercase
- IsMACAddress
- IsMagnetURI
- IsMilitaryTime
- IsMimeType
- IsMobilePhone
- IsMongoId
- IsMultibyte
- IsNegative
- IsNotEmpty
- IsNotEmptyObject
- IsNotIn
- IsNumber
- IsNumberString
- IsObject
- IsOctal
- IsOptional
- IsPassportNumber
- IsPhoneNumber
- IsPort
- IsPositive
- IsPostalCode
- IsRFC3339
- IsRgbColor
- IsSemVer
- IsString
- IsStrongPassword
- IsSurrogatePair
- IsTaxId
- IsTimeZone
- IsUppercase
- IsUrl
- IsUUID
- IsVariableWidth
- Length
- Matches
- Max
- MaxDate
- MaxLength
- Min
- MinDate
- MinLength
- NotContains
- NotEquals
- registerEnv
- Transform
- TransformToBoolean
- Validate
- ValidateBy
- ValidateIf
- ValidateNested
- ValidatePromise
