2.0.5 • Published 1 year ago

jsonschema-mask v2.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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;
}
2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.1

1 year ago

1.3.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago