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

changeline

v1.11.0

Published

Search and replace in lines of files across directories.

Downloads

20

Readme

changeline

Search and replace in lines of files across directories.

Changeline is your basic file search and replace. But it goes beyond regular expressions and paths. You must submit a list of files via STDIN, so it is up to you to select a directory scan program. You can use UNIX find with a *.html wildcard for example.

Furthermore, there is no question about matches spanning lines. Changeline simply sees one line at a time. It uses node readline under the hood.

Finally, changeline is a precision device aimed at altering lines of code without the need for AST processing. You can for example target CSS Class Names in .css/.html and .js/es6 files, and it will plow through ES7 and CSS4 and whatever else comes its way.

Installation

changeline is a command line program, and it is installed via npm which comes along with node. Please install node first, and then run npm install -g changeline to get changeline onto your system.

Usage

After installation via npm install -g changeline you should begin by piping in a list of files separated by a new line. Example of making a dynamic list find . -name example.html -print or cat my-files-to-change.txt where my-files-to-change.txt contains a list of full paths to files needing changes.

Upon a list of paths arriving via STDIN changeline will apply functions to test, and replace data. See test-transformers.js for a more serious example.

module.exports = [
  // JS
  {
    description: "Update bark to meow.",
    search: function(line){ if(line === 'bark') return true; },
    replace: function(line){ return 'meow' },
  },
  // ES6
  {
    description: "Update Bort to Bart.",
    search: line => line === 'Bort',
    replace: line => 'Bart',
  },
]

Usage: changeline [options]

Options:

  -h, --help                 output usage information
  -V, --version              output the version number

  -v, --verbose              Make changeline verbose

The CAS backup concept is similar to Content Addressable Storage prior to altering a file a copy is saved in ~/.changeline a simple index keeps track of hashes, timestamps and original file locations.

  -c, --cas                  Make cas backup before replacement. (recommended)
  --cas-home [path]          Path of cas backups (optional)

A plain old filename.ext.bak is available as well. -b, --backup Make backup before replacement. (optional) --backup-extension [ext] Extension to use for backup files (optional)

You must use the -r/-t flags to do useful things:

  -r, --replace              Perform replacement (required for actual replacement)
  -t, --transformers [path]  Transformer module. (required for specifying what to replace)

The transformer format is ES6 by default and very easy to manage:

module.exports = [
  {
    description: "Update Bort to Bart.",
    search: line => line === 'Bort', // return truthy value to trigger replace
    replace: line => 'Bart', // return updated line content
  },
]

Features and Concepts

Changeline accepts a list of files from the command line via STDIN. This means you can use operating system utilities for file search. example: find . -name test.html -print | changeline -t transformers.js -r -c;

Changeline uses es6 functions for searching an replacing, see transformers.js

Changeline makes backups see --help

Snippets

A quick non-destructive one-liner, run it in changeline's directory:

cp test.html test-tmp.html; echo -e "\nBEFORE"; cat test-tmp.html; echo; find . -name test-tmp.html -print | ./index.js -v -r -c -t ./test-transformers.js; echo -e "\nAFTER"; cat test-tmp.html; echo; rm test-tmp.html;

Links

npm: https://www.npmjs.com/package/changeline
github: https://github.com/fantasyui-com/changeline

MIT License

Written by Captain Fantasy, Copyright (c) 2016 FantasyUI