@creanick/cssinjector

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i @creanick/cssinjector

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

2.7 kB

Total Files

3

Last publish

Collaborators

  • creanick