An open API service indexing awesome lists of open source software.

https://github.com/9technology/meta-props

Page configuration via meta tags.
https://github.com/9technology/meta-props

config meta property props

Last synced: 10 months ago
JSON representation

Page configuration via meta tags.

Awesome Lists containing this project

README

          

# meta-props

[![Build Status](https://travis-ci.org/9technology/meta-props.svg?branch=master)](https://travis-ci.org/9technology/meta-props) [![Coverage Status](https://coveralls.io/repos/github/9technology/meta-props/badge.svg?branch=master)](https://coveralls.io/github/9technology/meta-props?branch=master)

Create key-valued hashes from a document's `meta` tags. Useful for reading static configurations from a page.

## Usage
---

```html



import metaProps from 'meta-props';
const props = metaProps();
console.assert(props.foo, 'bar');

```

#### Objects

Properties can be also be deep using a separator, default `:` colon.

```html

const props = metaProps('name');
console.assert(props.foo, 'foo');
console.assert(props.bar.baz, 'baz');

```

#### Arrays

Naming the same `meta` tag will convert the values into an `Array`.

```html

const props = metaProps();
console.assert(Array.isArray(props.array));
console.log(props.array); // ['foo', 'bar', 'baz']

```

#### Casting Value Types

Values can also be type casted via the `type` attribute in the tag.

```html

const props = metaProps();
console.log(typeof props.number); // number
console.log(typeof props.string); // string
console.log(typeof props.boolean); // boolean
console.log(typeof props.json); // object
console.log(typeof props.json.foo); // boolean
console.assert(props.empty === null);

```

## API
---

#### `metaProps([query=null, [separator=":"]])`
- `query` _String_ Used to select prefixed meta tag names.
- `separator` _String_ The split character for building deep hashes.

## License
---

[BSD-3-Clause](LICENSE)

Copyright (c) 2016 [9Technology](https://github.com/9technology)