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

soaping

v1.1.4

Published

Searches for unused files(.js, .png, etc) doing string comparison in a given file.

Downloads

5

Readme

Soaping

This dev-dependency is intended for erasing unused files in a project. It basically identifies if a file name is being imported or required by other files. If a specific file (*.js, *.png, etc.) is not being called from anywhere else, it's a candidate for being erased.

It's perfect for web projects that are using the import or require keyword.

This library only suggests wich files you could delete. With that information you could decide which files remove from your project.

Use cases

  • Find images in a project that are not being used anywhere
  • Delete js files that got unused in a particular project

Install library

npm install --save-dev soaping

Install library and create config.js file

npm install --save-dev soaping && cp ./node_modules/config.js config.js

Config file

To get this going, you will have to create a config file. Below you have an example of config.js file. You'll need to execute this config file by doing the following:

node config.js

This is how it works:

  • you specify a directory of files that you want to find out whether they are being used or not
  • you specify a directory where you will do the search. In this directory, all the files will be scanned
  • This scanning process will do a string comparison finding out if a given file name is being imported
  • If the file name is not being recalled from anywhere else, that file name will be shown as files to delete

Configuration of the config file

// Example of config.js file
const soaping = require('soaping');

const PATH_TO_ICON_RESOURCES = './src/resources/images';
const PATH_TO_ICON_ASSETS = './components/ui/icon/assets';
const PATH_TO_UI = './commons/components/ui';
const PATH_TO_SRC = './src';


const settings = {
  stages: [
    {
      fileFilter: ['*.png'],
      excludeFiles: ['/*@[1-3]x.png'],
      listOfSources: [PATH_TO_ICON_ASSETS, PATH_TO_ICON_RESOURCES],
      listOfEnds: [PATH_TO_SRC, PATH_TO_UI],
      keepExtension: true,
    },
    {
      fileFilter: ['*.js'],
      excludeFiles: ['.test*', 'App'],
      listOfSources: [PATH_TO_UI, PATH_TO_SRC],
      listOfEnds: [PATH_TO_UI, PATH_TO_SRC],
      keepExtension: false,
    },
  ],
};

soaping(settings, (ixStage, fileName) => {
  console.log('Stage:', ixStage, ' - File to Remove:', fileName);
});

There a few things to mention of this config file:

  • fileFilter: will search only this type of files (e.g.: *.png, *.js)
  • excludeFiles: all the file names that don't need to be included in the scanning process
  • listOfSources: directories that contain the files that are going to be searched (it takes only the names of the files as strings)
  • listOfEnds: directories that contain the files where the scanning will be performed. This scanning process will try to string match a given file name inside the content of a given file from listOfEnds.
  • keepExtension: some files are imported with full extension while others not. Usually images are imported using *.jpg. Use true in this case.
  • the soaping function takes the settings object and receives a callback
  • this callback has two arguments: ixStage and fileName
  • ixStage: stage of scanning process
  • fileName: the file name that should be removed

Tips

  • Search images with keepExtension: true because images are called with its extension:
import imageExample from '../../imageExample.png';
var imageExample = require("../../imageExample.png");
  • Search files with keepExtension: false because js files are called without its extension:
import jsFileExample from '../../jsFileExample';
var jsFileExample = require("../../jsFileExample");

License

MIT