Socket
Socket
Sign inDemoInstall

jsonschema-mask

Package Overview
Dependencies
8
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jsonschema-mask

A well tested lightweight library that takes in a JSON schema and a JSON object and ensures that extra properties are removed from the object. It requires two peer dependencies of [ajv](https://github.com/ajv-validator/ajv) and [jsonpointer](https://githu


Version published
Maintainers
1
Install size
63.8 MB
Created

Readme

Source

JSONSchema mask

A well tested lightweight library that takes in a JSON schema and a JSON object and ensures that extra properties are removed from the object. It requires two peer dependencies of ajv and jsonpointer

Installation

npm i jsonschema-mask
# Or
yarn add jsonschema-mask

Usage

import { maskData } from "jsonschema-mask";

const schema = {
    type: "object",
    properties: {
        username: {
            type: "string",
        },
    },
    required: ["username"],
    additionalProperties: false,
};

const rawData = {
    username: "mock-username",
    password: "mock-hash",
    email: "mock-email",
};

const maskOptions: IMaskOptions = {};

const maskedData = maskData(schema, "#", rawData, maskOptions);
/*
data now has extra properties stripped
{
    username: "mock-username",
};
*/

Options

export interface IMaskOptions {
    /* Controls whether type errors are masked, default: true */
    readonly shouldMaskTypeErrors?: boolean;
    /* Optional callback when there is a missing property */
    readonly onMissingProperty?: (error: ErrorObject) => void;
    /* Optional callback when there is an additional property */
    readonly onAdditionalProperty?: (error: ErrorObject) => void;
    /* Optional callback when there is a type error */
    readonly onTypeError?: (error: ErrorObject) => void;
}

FAQs

Last updated on 05 Dec 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc