{"library":"rttc","title":"RTTC: Runtime Type-Checking for JavaScript","description":"RTTC (Runtime Type-Checking) is a lightweight, recursive type system for JavaScript designed to provide flexible, performant type guarantees on an as-needed basis, particularly valuable in Node.js environments for preventing common async callback errors. Unlike build-time type checkers, RTTC operates at runtime, validating and coercing data without requiring changes to the development stack or build tools. It is currently at version 10.0.1 and is actively maintained, with major version updates occurring when breaking changes necessitate. Key differentiators include its focus on runtime validation and coercion, deep traversal of data structures, and its integral role in core Node-Machine project utilities, the Sails.js framework, Waterline drivers, and various machinepacks, making it a foundational component for many tools in that ecosystem.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install rttc"],"cli":null},"imports":["const rttc = require('rttc');","const rttc = require('rttc');\nrttc.validateStrict('number', 999);","const rttc = require('rttc');\nrttc.coerce('number', '999');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const rttc = require('rttc');\n\nconst schema = [\n  { name: 'string', age: 'number', friends: ['string'] }\n];\n\nconst data = [\n  { name: 'Karl', age: 258 },\n  { name: 'Samantha', age: '937' },\n  { name: 'Lupé', age: 82, friends: ['Henry', 'Mario', undefined] },\n  { name: 'Andres', age: '22' },\n  { age: ['nonsense!'] }\n];\n\nconst coercedData = rttc.coerce(schema, data);\n\nconsole.log(coercedData);\n/*\nOutput:\n[\n  { name: 'Karl', age: 258, friends: [] },\n  { name: 'Samantha', age: 937, friends: [] },\n  { name: 'Lupé', age: 82, friends: ['Henry', 'Mario'] },\n  { name: 'Andres', age: 22, friends: [] },\n  { name: '', age: 0, friends: [] }\n]\n*/","lang":"javascript","description":"Demonstrates `rttc.coerce` applying a complex recursive schema to an array of objects, coercing values to their base types when possible and filling in missing required fields with base values, never throwing errors.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}