replace-outside-strings
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Replace Outside Strings

Greenkeeper badge

A CLI tool that will replace outside strings that you provide and keep whatever is between the two strings.

demo

  • CLI usage:
replace-outside-strings -d "*.scss" --s1 "@include transform\(" --r1 "transform: " --s2 "\);" --r2 ";"
  • API usage:
const newContent = replace(fileContent, strings)

Table of Contents

Install

npm i -g replace-outside-strings
  • OR run with:
npx replace-outside-strings ...

CLI

  • Usage: cli.ts [options]
Flag Type Description
-f, --file string Path of file you want to replace
-d, --directory string String glob of directory you want to replace files in recursively
--s1 string Beginning string you want to replace
--s2 string Text content you want to replace the beginning string with
--r1 string Ending string you want to replace
--r2 string Text content you want to replace the ending string with
-n, --no-dry-run boolean By default dry run is set which means files will not be written unless you add this
-h, --help boolean Output usage information
  • Note: make sure to double quote when passing in directory like: -d "mydir/**/*.js"

Examples

  • Test that css mixin replace works with dry run (new file contents will be printed to console):
replace-outside-strings -d "themes/*-theme/src/css/**/*.scss" --s1 "@include transform\(" --r1 "transform: " --s2 "\);" --r2 ";"
  • Do it for real!
replace-outside-strings --no-dry-run -d "themes/*-theme/src/css/**/*.scss" --s1 "@include transform\(" --r1 "transform: " --s2 "\);" --r2 ";"

API

import { replace } from 'replace-outside-strings' //or
const { replace } = require('replace-outside-strings')
 
const newContent = replace(fileContent, strings)
// 2nd arg in shape of:
/* interface strings {
     s1: string
     s2: string
     r1: string
     r2: string
*/ }
 
console.log(newContent)
// Will return text if replace occurred.
// Will return false if nothing happened.

How globs work

License

MIT © Ryan Garant

Package Sidebar

Install

npm i replace-outside-strings

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

56 kB

Total Files

14

Last publish

Collaborators

  • protoevangelion