![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
mol_data_all
Advanced tools
Defines static typed DTO with strict runtime validation and user friendly error messages like:
Defines static typed DTO with strict runtime validation and user friendly error messages like:
["friends"][0]["phone"] undefined is not any of variants
undefined is not a string
undefined is not a number
// Base Type
const PersonDTO = $mol_data_record({
name : $mol_data_string ,
age : $mol_data_optional( $mol_data_integer ) ,
birthday : $mol_data_pipe( $mol_data_string , $mol_time_moment ) ,
})
// Derived Type
const UserDTO = $mol_data_record({
... PersonDTO.config,
phone: $mol_data_variant( $mol_data_string , $mol_data_integer ),
mail: $mol_data_email,
})
// Ensure this is a User
const jin = UserDTO({
name : 'Jin' ,
age : 33 ,
birthday : '1984-08-04T12:00:00Z' ,
phone : 791234567890,
mail : 'foo@example.org' ,
})
// typeof jin === {
// readonly name: string;
// readonly age?: number | undefined;
// readonly birthday: $mol_time_moment;
// readonly phone: string | number;
// readonly mail: string;
// }
// Allow only Users
function printName( user : typeof UserDTO.Value ) {
console.log( user.name )
}
printName( jin )
// Wrong json from server
const json = {
name : 'Jin' ,
age : 33 ,
birthday : '1984-08-04T12:00:00Z' ,
phone : 791234567890,
mail : '</script>' , // !
} as any
// Runtime error: ["mail"] </script> is not a /.+@.+/
printName( UserDTO( json ) )
const Weight = $mol_data_nominal({ Weight : $mol_data_integer })
const Length = $mol_data_nominal({ Length : $mol_data_integer })
let len = Length(10)
len = Length(20) // Validate
len = 20 as typeof Length.Value // Cast
len = 20 // Compile time error
len = Weight(20) // Compile time error
len = Length( 20.1 ) // Run time error
const Duration = $mol_data_pipe(
$mol_data_variant(
$mol_data_string ,
$mol_data_integer ,
) ,
$mol_time_duration ,
)
JSON.stringify( Duration( 'P1D' ) ) // "P1DT"
JSON.stringify( Duration( 1000 ) ) // "PT1S"
npm install mol_data_all
import {
$mol_data_nominal as Nominal,
$mol_data_integer as Integer,
} from "mol_data_all"
const Int = Nominal({ Int: Integer })
const i = Int(1)
const j: typeof Int.Value = Int( i + 1 )
FAQs
Defines static typed DTO with strict runtime validation and user friendly error messages like:
The npm package mol_data_all receives a total of 962 weekly downloads. As such, mol_data_all popularity was classified as not popular.
We found that mol_data_all demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.