object-metadata
set and get metadata on objects. Inspired by clojure/meta
Last updated 3 years ago by micimize .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install object-metadata 
SYNC missed versions from official npm registry.

Object Metadata

simple metadata setting and getting for javascript inspired by clojure/meta

Overview

  • Exports { default: meta, get, META }
  • meta has the signature meta(data) => obj => obj. This writes the given data to obj[META]
  • metadata can be retrieved by get(obj) => data, meta.get(obj) => data, or obj[META] => data

Usage

import meta from 'object-metadata'

const arrayify = meta({
  description: `wraps defined non-array elements in an array,
                always returns an array.`,
  examples: [
    {input: ['foo'], output: ['foo']},
    {input: 'foo', output: ['foo']},
    {input: undefined, output: []}
  ]
})(
  function arrayify(val){
    return Array.isArray(val) ? val : (val !== undefined ? [val] : [])
  }
)

Object.keys(meta.get(arrayify))

//=> ['description', 'examples']

meta.get(meta)
/* =>
  {
    description: "Add meta data to an object under the symbol exported by this module as META",
    usefulness: "attaching metadata to objects can be used in domain driven development, documentation, and testing"
  }
*/

Note: metadata can not be set on primitive types.

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |