Skip to content

ivoilic/style-implant

Repository files navigation

style-implant

NPM version NPM downloads

Implant style tags where you need them.

Installation

yarn add style-implant
npm install style-implant

Example

import styleImplant from 'style-implant';

const css = `
  body {
    margin: 0;
  }
`;

const options = {
  attributes: { 'data-implanted': '💉' },
  insertAt: 'top',
  preserveOrder: true,
};

styleImplant(css, options);

Options

{
  attributes?: {string: string};
  insertAt?: string = 'bottom';
  preserveOrder?: boolean = false;
}
  • attributes: Takes an object where the keys are attribute names and the values are the attribute values.
  • insertAt: When 'top' style tags will be implanted in the top of the head rather than the bottom. Warning: This will reverse the order in which tags load as the newest tag will always be first instead of last.
  • preserveOrder: When enable multiple style tags will be implanted in order from oldest to newest within the same parent element. This option is disabled by default to match the output of style-inject but it's reccomended that you enable it for a better experience. Future versions may enable this by default.

Replacing style-inject

style-implant was designed to be a drop in replacement for style-inject. All versions until v0.4.0 of style-implant will not cause breaking changes for previous users of style-inject. These versions will only add more options. This package improves on style-inject by adding critical options, TypeScript support, and tests!

License

Based on style-inject by EGOIST

Licensed under the MIT license

© 2021 Ivo Ilić

About

Implant style tags where you need them.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published