1.0.1 • Published 6 years ago

@creanick/cssinjector v1.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

Css Injector

Inject css rules to style tag of document head dynamically with javascript

Note: Actual file written wtih javascript es6 syntax so for supporting old browser you have to compile it to older version javascript

Installation

npm install @creanick/cssinjector

Import

const CssInjector = require('@creanick/cssinjector');

Syntax

CssInjector.inject(cssString:String,insertTop:Boolean) : Boolean;

CssString : css style as string which you want to inject if it fails parsing css String as string it return false otherwise return true after successfully inject css rules;

InsertTop : default false, if true and already style tag exist then it inject css rules at the top of any existing css rules

Example

InsertTop : false

CssInjector.inject(`
    body{
        margin: 0;
        background: red;
    }
    div{
        display: flex;
    }
`);

InsertTop : true

CssInjector.inject(`
    body{
        margin: 0;
        background: red;
    }
    div{
        display: flex;
    }
`,true);

It's is under ISC license, it can be use in any commercial and non commercial project without any charges