npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

replace-styles

v1.0.11

Published

Replace any css property in all specified files in config.

Downloads

5

Readme

Follow me Sponsors MIT License Node Version

The easiest way to replace style properties in many style files and @import or @include all needed sass dependencies!

Perfect tool if you want to replace multiple css properties with just a second, what is needed is just to provide config with your selectors, imports, replaces and the replace-styles will do the work for you!


Why to use the replace-styles:

  • Easy way to replace multiple css properties in any of founded files.
  • Will replace each css properties which is match the replace array.
  • Easy to specify path to your files via glob. Example "src/*/.{scss,sass}" which will select all files in src/ folder and nested ones with ends with .scss or .sass;
  • You can provide multiple selectors for search in files.
  • Will keep the older @imports and @includes and will combine with your new provided in config following the best practice.
  • Provide nice message with how many files found and list output of them.
  • Provide nice output with files which were change.
  • Easy to make a configuration.

Table of contents


Installation

  • Via yarn:
yarn add replace-styles -D
  • Via npm:
npm install replace-styles --save-dev

How to use?

Full setup

import replaceStyles from "replace-styles";

const config = {
  paths: "src/**/*.{scss,sass}",
  selectors: ["color: "],
  imports: ["@use '@my/style' as style;", "@import '@test/style';"],
  replaces: [
    {
      selectors: ["color: "],
      replace: [
        {
          from: "red",
          to: "style.$red",
        },
      ],
    },
  ],
};

replaceStyles(config);

API

| Method | Usage | | ------------------- | ---------------------------------------------------------------------------- | | replaceStyles() | Provide config and will replace everything based on specification in config. | | config | Object. |

Example config:

const config = {
  paths: "src/**/*.{scss,sass}",
  imports: ["@use '@my/style' as style;"],
  replaces: [
    {
      selectors: ["color: ", "background-color: "],
      replace: [
        {
          from: "#bde5bd",
          to: "style.$green",
        },
        {
          from: "#ffffff",
          to: "style.$white",
        },
        {
          from: "blue",
          to: "#0000FF",
        },
      ],
    },
    {
      selectors: ["padding: ", "margin: "],
      replace: [
        {
          from: "5px",
          to: "style.$small-size",
        },
      ],
    },
  ],
};

| Config property | Type | Description | | --------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | | paths | Array - [] | Path to files which will be replaces. Support glob selector. | | imports | Array - [] | Add @imports or @use to the top of each selected file. Will conbine existing ones with new ones to follow the order via first @use and then all @imports. | | replaces | Array of objects - object[] | Array of objects {selectors: ['string'], replace:[{from:, to:}]}. Will replace evetything which match the selector in files from -> to property. | | encoding? | string | Encoding of the files. By default will be 'utf8' |

Replaces array structure:

replaces: [
  {
    selectors: ["string of selectors"],
    replace: [
      {
        from: "string to find to replace",
        to: "string to replace",
      },
    ],
  },
];

Examples:

example 1:

  1. Find files in src folder wich end with .scss;
  2. Replace all red colors with blue ones.

Setup for example 1:

import replaceStyles from "replace-styles";

const config = {
  paths: "src/**/*.scss}",
  imports: [""],
  replaces: [
    {
      selectors: [': '],
      replace: [
        from: "red",
        to: "blue",
      ]
    }
  ]
};

replaceStyles(config);

Example 2:

  1. Find files in src folder which end with .scss;
  2. Select all css properties.
  3. Add '@use '@test/style' as style;' of the top of the file.
  4. Replace all red colors with style.$red sass variable.

Setup for example two:

import replaceStyles from "replace-styles";

const config = {
  paths: "src/**/*.scss}",
  imports: ["@use '@test/style' as style;"],
  replaces: [
    {
      selectors: [': '],
      replace: [
        from: "red",
        to: "style.$red",
      ]
    }
  ]
};

replaceStyles(config);

Developer Support:

  • If you saw some issue/bug 🐛 related to the specific release version.
  • If you want some new feature or change to be added/implemented. 😊

Please, contact the creator of the replace-styles, so he will be able to fix or improve it:

Kristiyan Velkov

Email: [email protected]

linkedin

portfolio

Support my work

If you like my work and want to support me to work hard, please donate via:

| Revolut | Buy me a coffee | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | |

Thanks a bunch for supporting me! It means a LOT 😍


Copyright ©️2024. All rights reserved.