@f/stringify-attrs

    1.0.5 • Public • Published

    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

    Keywords

    none

    Install

    npm i @f/stringify-attrs

    DownloadsWeekly Downloads

    1

    Version

    1.0.5

    License

    MIT

    Last publish

    Collaborators

    • f