Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/protoevangelion/replace-outside-strings
Replace outside strings & keep what's on the inside
https://github.com/protoevangelion/replace-outside-strings
Last synced: 5 days ago
JSON representation
Replace outside strings & keep what's on the inside
- Host: GitHub
- URL: https://github.com/protoevangelion/replace-outside-strings
- Owner: protoEvangelion
- License: mit
- Created: 2018-12-07T18:44:20.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-09T20:21:33.000Z (over 3 years ago)
- Last Synced: 2024-04-28T03:33:26.726Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.61 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Replace Outside Strings
[![Greenkeeper badge](https://badges.greenkeeper.io/protoEvangelion/replace-outside-strings.svg)](https://greenkeeper.io/)
> A CLI tool that will replace outside strings that you provide and keep whatever is between the two strings.
![demo](assets/replace-outside-strings.png)
- **CLI usage**:
```bash
replace-outside-strings -d "*.scss" --s1 "@include transform\(" --r1 "transform: " --s2 "\);" --r2 ";"
```- **API usage**:
```javascript
const newContent = replace(fileContent, strings)
```# Table of Contents
- [Replace Outside Strings](#replace-outside-strings)
- [Table of Contents](#table-of-contents)
- [Install](#install)
- [CLI](#cli)
- [Examples](#examples)
- [API](#api)
- [How globs work](#how-globs-work)
- [License](#license)## Install
```bash
npm i -g replace-outside-strings
```- OR run with:
```bash
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_):
```bash
replace-outside-strings -d "themes/*-theme/src/css/**/*.scss" --s1 "@include transform\(" --r1 "transform: " --s2 "\);" --r2 ";"
```- Do it for real!
```bash
replace-outside-strings --no-dry-run -d "themes/*-theme/src/css/**/*.scss" --s1 "@include transform\(" --r1 "transform: " --s2 "\);" --r2 ";"
```## API
```javascript
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
- When passing a directory, make sure you understand globs
- https://www.npmjs.com/package/glob#glob-primer## License
MIT © [Ryan Garant](https://rhino.codes)