1.0.5 • Published 8 years ago

@f/stringify-attrs v1.0.5

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

stringify-attrs

Build status Git tag NPM version Code style

Turn an attributes object into a string

Installation

$ npm install @f/stringify-attrs

Usage

var stringifyAttrs = require('@f/stringify-attrs')

stringifyAttrs({href: 'http://www.google.com', class: 'link'}) === ' href="http://www.google.com" class="link"'

API

stringifyAttrs(attrs, skip)

  • attrs - An object of key/value pairs representing attributes
  • skip - Optional. Map of attribute names to skip. E.g. {innerHTML: true}. This is useful if there are certain attribute names that don't make sense when rendered as strings.

Returns: A string containing the attributes in key=value style. Returns empty string if falsy value passed.

Prepended space

The returned string starts with a prepended space (e.g. ' class="link"'). This makes the code short, simpler, and faster, and also comports better with the most common use-case, which is rendering a DOM element as a string (if you don't have the prepended space, you have to again awkwardly check whether attrs is empty).

License

MIT

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago