1.0.2 • Published 5 years ago

replace-outside-strings v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

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]
FlagTypeDescription
-f, --filestringPath of file you want to replace
-d, --directorystringString glob of directory you want to replace files in recursively
--s1stringBeginning string you want to replace
--s2stringText content you want to replace the beginning string with
--r1stringEnding string you want to replace
--r2stringText content you want to replace the ending string with
-n, --no-dry-runbooleanBy default dry run is set which means files will not be written unless you add this
-h, --helpbooleanOutput 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