# object-normalizer

> javascript object normalizer.

Latest version **1.3.1** (published 2017-04-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install object-normalizer
pnpm add object-normalizer
yarn add object-normalizer
bun add object-normalizer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2017-04-26 |
| First published | 2017-04-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | yichen |
| Maintainers | unicreators |
| Keywords | normalize, normalizer, object-normalizer |

## Links

- npm: https://www.npmjs.com/package/object-normalizer
- Repository: https://github.com/unicreators/object-normalizer
- Homepage: https://github.com/unicreators/object-normalizer#readme
- Issues: https://github.com/unicreators/object-normalizer/issues
- npm.io page: https://npm.io/package/object-normalizer

## Recent versions

- 1.3.1 (latest) — 2017-04-26
- 1.3.0 — 2017-04-23
- 1.2.0 — 2017-04-22
- 1.1.0 — 2017-04-22
- 1.0.0 — 2017-04-22

## README

## ObjectNormalizer

object normalizer.


## Install

```sh
$ npm install object-normalizer
```

## Usage

### Normal

```js

const schema = {
    'prop1': function (value) {
        if (value == undefined)
            value = 1;
        return value;
    },
    'prop2': function (value) {
        if (typeof value !== 'function')
            throw new Error(`'prop2' must be of Function type.`);
        return value;
    }
};

const defaultPropertyName = 'prop2';

let nor = new ObjectNormalizer(schema, defaultPropertyName);
let r = nor.normalize(function () { });

console.log(r);
// { prop1: 1, prop2: [Function] }


```



### Multiple

```js

const schema = {
    parent1: function (value) {
        if (value == undefined) value = 'parent1';
        return value;
    },
    parent2: {
        schema: {
            'prop1': function (value) {
                if (value == undefined) value = 1;
                return value;
            },
            'prop2': function (value) {
                if (typeof value !== 'function')
                    throw new Error(`'prop2' must be of Function type.`);
                return value;
            }
        },
        defaultProperty: 'prop2'
    }
};

const defaultPropertyName = 'parent2';

let nor = new ObjectNormalizer(schema, defaultPropertyName);
let r = nor.normalize(function () { return 'hello!'; });

console.log(r);
// { parent1: 'parent1', parent2: { prop1: 1, prop2: [Function] } }

console.log(r.parent2.prop2());
// hello!

```



### Array

```js

const schema = {
    // array
    'prop1': [function (value) {
        if (value == undefined)
            value = 1;
        return value;
    }],
    'prop2': function (value) {
        if (typeof value !== 'function')
            throw new Error(`'prop2' must be of Function type.`);
        return value;
    },
    // to array, not validate
    'prop3': []
};

const defaultPropertyName = 'prop2';

let nor = new ObjectNormalizer(schema, defaultPropertyName);
let r = nor.normalize(function () { });

console.log(r);
// { prop1: [], prop2: [Function], prop3: [] }


```



### Root array

```js

// array
const schema = [{
    'prop1': function (value) {
        if (value == undefined)
            value = 1;
        return value;
    },
    'prop2': function (value) {
        if (typeof value !== 'function')
            throw new Error(`'prop2' must be of Function type.`);
        return value;
    }
}];

const defaultPropertyName = 'prop2';

let nor = new ObjectNormalizer(schema, defaultPropertyName);
let r = nor.normalize(function () { });

console.log(r);
// [{ prop1: 1, prop2: [Function] }]


```




### License

[MIT](LICENSE)

---
_Source: https://npm.io/package/object-normalizer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
