Wondering what’s next for npm?Check out our public roadmap! »

    addstyles

    1.0.5 • Public • Published

    addstyles unstable

    Insert CSS styles into an HTML document and register new font-face for the current web page by URL.

    Module use pure javascript code without dependents.

    npm install addstyles

    Usage

    import addStyles from 'addstyles'; // or import {insertStyles} from 'addstyles';
     
    addStyles.insertStyles('h1 { font-size: 14px }')
    //=> <head><style> h1 { ... }</style></head>

    For add font-face to your page:

    import addStyles from 'addstyles'; // or import {addFont} from 'addstyles';
     
    //Font URL w/o extension inserts eot, woff2, woff, ttf, svg and otf versions
    addStyles.addFont('//cdn.jsdelivr.net/font-hack/2.020/fonts/eot/latin/hack-regular-latin-webfont',
                      `font-family: Hack; font-weight: normal;`)
     
    //Font URL with extension inserts only target font file
    addStyles.addFont('./wavefont.otf', 'wavefont');

    API

    insertStyles(styles, [options]) -> void

    addFont(fontUrl, cssString|fontName)

    addFont(fontUrlList, cssString|fontName)

    Attach font to the page, apply additional parameters, which are whether font name or @font-face properties, eg font-family: ; font-style: ; font-weight: .

    styles

    Required. The string of styles to insert into the DOM.

    options
    id

    Calling insertStyles with the same options.id multiple times will re-use the same <style> element each time.

    Related

    Install

    npm i addstyles

    DownloadsWeekly Downloads

    6

    Version

    1.0.5

    License

    MIT

    Unpacked Size

    6.33 kB

    Total Files

    3

    Last publish

    Collaborators

    • avatar