# hfb

> Builder for Hf Representations

Latest version **0.1.3** (published 2015-11-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install hfb
pnpm add hfb
yarn add hfb
bun add hfb
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2015-11-01 |
| First published | 2015-11-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Stephen Mizell |
| Maintainers | smizell |

## Links

- npm: https://www.npmjs.com/package/hfb
- npm.io page: https://npm.io/package/hfb

## Dependencies (6)

- [chai](https://npm.io/package/chai.md) ^3.4.0
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.0.14
- [lodash.assign](https://npm.io/package/lodash.assign.md) ^3.2.0
- [lodash.isarray](https://npm.io/package/lodash.isarray.md) ^3.0.4
- [lodash.isempty](https://npm.io/package/lodash.isempty.md) ^3.0.4
- [lodash.isobject](https://npm.io/package/lodash.isobject.md) ^3.0.2

## Recent versions

- 0.1.3 (latest) — 2015-11-01
- 0.1.1 — 2015-11-01
- 0.1.0 — 2015-11-01

## README

# Hf Builder (hfb)

[![Build Status](https://travis-ci.org/smizell/hfb.svg)](https://travis-ci.org/smizell/hfb)

Functions for building [Hf representations](https://github.com/smizell/hf).

- [Hf Builder (hfb)](#hf-builder-hfb)
	- [Install](#install)
	- [Usage](#usage)
		- [`hfb.addAttributes`](#hfbaddattributes)
		- [`hfb.addTransition`](#hfbaddtransition)
		- [`hfb.addMetaAttributes`](#hfbaddmetaattributes)
		- [`hfb.addMetaLink`](#hfbaddmetalink)
	- [Developing and Contributing](#developing-and-contributing)
	- [License](#license)

## Install

```sh
npm install hfb --save
```

## Usage

### `hfb.attributes`

Takes an Hf object and an attributes object. If `attributes` does not exist, it adds it to the Hf object. It then returns the `attributes` property.

```js
var attributes = hfb.attributes({}); // now {attributes: {}}
```

### `hfb.addAttributes`

Takes an Hf object and an attributes object. If `attributes` does not exist, it adds it to the Hf object. If the `attributes` exist, it does a merge of the given attributes.

```js
var hfObj = hfb.addAttributes({}, {foo: 'bar'});
```

The `hfObj` variable now has:

```js
{
  attributes: {
    foo: 'bar'
  }
}
```

If you then do the following:

```js
hfb.addAttributes(hfObj, {hello: 'world'});
```

The value of `hfObj` would be.

```js
{
  attributes: {
    foo: 'bar',
    hello: 'world'
  }
}
```

### `hfb.transitions`

Takes an Hf object and a transition object. If the `transitions` array does not exist, it adds it to the Hf object. It then returns the `transitions` array.

```js
var transitions = hfb.transitions({}); // now {transitions: []}
```

### `hfb.addTransition`

Takes an Hf object and a transition object. If the `transitions` array does not exist, it adds it to the Hf object. It then adds the given transition to the array.

```js
var hfObj = hfb.addAttributes({}, {
  tag: 'link',
  rel: 'next',
  href: '/user/2'
});
```

The `hfObj` variable now has:

```js
{
  transitions: [
    {
      tag: 'link',
      rel: 'next',
      href: '/user/3'
    }
  ]
}
```

If you then do the following:

```js
hfb.addAttributes(hfObj, {
  tag: 'link',
  rel: 'prev',
  href: '/user/1'
});
```

The value of `hfObj` would be.

```js
{
  transitions: [
    {
      tag: 'link',
      rel: 'next',
      href: '/user/3'
    },
    {
      tag: 'link',
      rel: 'prev',
      href: '/user/1'
    }
  ]
}
```

### `hfb.addMetaAttributes`

Acts just like `hfb.addAttributes` except for meta attributes. If the `meta` object is not there, it creates it. If the `attributes` for the meta object is not there, it creates it. If `meta.attributes` is there, it does a merge of the given attributes.

```js
var hfObj = hfb.addMetaAttributes({}, {foo: 'bar'});
```

The `hfObj` variable now has:

```js
{
  meta: {
    attributes: {
      foo: 'bar'
    }
  }
}
```

### `hfb.addMetaLink`

Acts just like `hfb.addMetaLink`. If the `meta` object is not there, it creates it. If the `links` array for the meta object is not there, it creates it. Once `meta.links` is there, it adds the given link.

```js
var hfObj = hfb.addMetaLink({}, {
  tag: 'link',
  rel: 'next',
  href: '/user/2'
});
```

The `hfObj` variable now has:

```js
{
  meta: {
    links: [
      {
        tag: 'link',
        rel: 'next',
        href: '/user/3'
      }
    ]
  }
}
```

### `hfb.wrap`

If you have a normal object that you'd like to wrap as an Hf object, you can use `hfb.wrap`. It only accepts `object` types and will return an empty array if it receives anything other than an object.

```js
var oldObj = {
	foo: 'bar'
};

var newObj = hfb.wrap(oldObj); // now {attributes: {foo: 'bar'}}
```

## Developing and Contributing

To test, you can run:

```sh
npm test
```

If you install nodemon, you can run `npm run develop`.

```sh
npm install nodemon -g
npm run develop
```

Contributions are welcome! Please open a pull request.

## License

This code is [licensed under the MIT license](./LICENSE).

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