Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check option #33

Closed
wants to merge 1 commit into from
Closed

Added check option #33

wants to merge 1 commit into from

Conversation

borodyadka
Copy link

Function that will check for should value be flattened or not.

Example:

const SCHEMA = {
    key1: {
        foo: 'foo',
        bar: 'bar'
    },
    key2: {
        $keep: true,
        test: 'test'
    }
};

let r = flat.flatten(SCHEMA, {
    check: (value) => {
        return !(value.$keep);
    }
});

console.log(JSON.stringify(r, null, 2));

Will print:

{
  "key1.foo": "foo",
  "key1.bar": "bar",
  "key2": {
    "$keep": true,
    "test": "test"
  }
}

I'm using it in my schema validator.

@borodyadka
Copy link
Author

ping @hughsk

@timoxley
Copy link
Contributor

@H8BIT I've suggested to @richardschneider in #36 that perhaps a mapKeys/mapValues option could a good solution for these types of problems… perhaps it also warrants filterKeys/filterValues?

For these types of things I usually use flat alongside split-object

e.g.

// note this is untested, just pseudo-code that might work
const filteredItems = split(flat(SCHEMA)).filter(({key, value}) => {
  return !value.$keep
})

const r = flat.unflatten(split.join(filteredItems))

@borodyadka borodyadka closed this Aug 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants