Registry / devops / map-schema

map-schema

JSON →
library0.3.0jsnpmunverified

map-schema is a Node.js library for validating and normalizing JavaScript objects against a defined schema. Current version 0.3.0 (sporadically updated, last release 2018) provides a chainable API to define fields with type checks, default values, custom normalizers, and validators. It supports validation error collection and is designed for scenarios like package.json normalization. Alternatives like Joi or Yup offer more features but map-schema is simpler for basic use.

npm install map-schema
INSTALL
IMPORT
SIG · MAP-SCHEMA
M
map-schema
devopsjavascriptv0.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Schema
const Schema = require('map-schema');
import Schema from 'map-schema';
Package uses CommonJS; ES module imports are not supported.

Shows how to create a schema with default values and a custom validator, then normalize an object.

const Schema = require('map-schema'); const fs = require('fs'); // Define a schema const schema = new Schema() .field('name', 'string') .field('version', 'string', { default: '0.1.0' }) .field('license', 'string', { default: 'MIT' }) .field('main', 'string', { validate: function(filepath) { return fs.existsSync(filepath); } }); // Normalize an object const obj = { name: 'my-package' }; schema.normalize(obj); console.log(obj); // => { name: 'my-package', version: '0.1.0', license: 'MIT' }
Debug
Known issues
gotchaThe normalize() method mutates the input object directly.
fix
Clone your object before passing it if you need to preserve the original: schema.normalize(Object.assign({}, obj))
affects: >=0.0.0
gotchaValidation errors are not thrown; they accumulate in schema.errors array.
fix
Check schema.errors after calling normalize() to see any validation failures.
affects: >=0.0.0
gotchaThe field method does not support nested objects or arrays of objects; schema is flat.
fix
Use dot notation keys (e.g., 'person.name') only works if you implement custom logic; the library does not handle nesting.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Schema is not a constructor
Importing the package incorrectly, e.g., using ES6 import syntax.
fix
Use const Schema = require('map-schema');
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
map-schema — npm install map-schema · libregistry