๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰like vcsode, string/texts can be replaced in file(s).

Overview

tiny-replace-files


Like vscode, simple utility to quickly replace text in one or more files.

Travis (.org) npm bundle size npm GitHub issues GitHub stars GitHub license

๐Ÿ“ฆ Getting Started

install

# npm 
npm install --save tiny-replace-files fast-glob

# yarn
yarn add tiny-replace-files fast-glob

# pnpm
pnpm install --save tiny-replace-files fast-glob

usage

Sync

import { replaceStringInFilesSync } from 'tiny-replace-files'

const options = {
  files: 'src/targets/index.js',
  from: 'test-plugin',
  to: 'self-name',
}

# await
const result = replaceStringInFilesSync(options)
console.info(result)
/**
[
  {
    file: './ques2.md',
    changed: true,
    matchCounts: 1,
    replaceCounts: 1
  }
]
*/

Async

import replaceStringInFiles from 'tiny-replace-files'

const options = {
  files: 'src/targets/index.js',
  from: 'test-plugin',
  to: 'self-name',
}

# await
const result = await replaceStringInFiles(options)
console.info(result)

# promise
replaceStringInFiles(options).then((res)=>{
    console.info(res)
}).catch(err=>{
    console.info(err)
})

Advanced usage

Replace a single file or glob

const options = {
  files: 'file',
};

Replace multiple files or globs

const options = {
  files: [
    'file1',
    'file2',
    'file3',
  ],
};

const options = {
  files: [
    'file1',
    'file2/**',
  ]
};

Replace by regex

const options = {
  from: /foo/g,
  to: 'bar',
};

from callback

const options = {
  files: 'file',
  from: (file) => new RegExp(file, 'g'),
  to: 'bar',
};

to callback

const options = {
    files: './ques2.md',
    from: 'quest 2',
    to: (match: string) => match.toUpperCase(),
    countMatches: true
}

Ignore file(s) or glob

const options = {
  ignore: './ignored/file',
};

const options = {
  ignore: [
    'path/**',
    'path2/index.html',
  ],
};

Disable globs

do not use fast-glob to get path. if you config this, you can uninstall fast-glob for reduce pkg size.

const options = {
  disableGlobs: true,
};

glob configuration

API passed to the fast-glob:

const options = {
  glob: {
    //Glob settings here
    dot: true, //E.g. to include file names starting with a dot
  },
};

Character encoding

Use a different character encoding for reading/writing files. Defaults to utf-8.

const options = {
  encoding: 'utf8',
};

freeze Run

freeze mode will do not replace & change, just run the process.

const options = {
  freeze: true,
};

โš™๏ธ Changelog

See CHANGELOG.

LICENSE

MIT

โœˆ๏ธ TODO

  • init lib
  • ๅฎŒๆˆ replaceStringInFiles ๅ‡ฝๆ•ฐๅผ€ๅ‘
  • ๅฎŒๆˆๅŒๆญฅๅ‡ฝๆ•ฐๅผ€ๅ‘
  • ๅฎŒๆˆๆต‹่ฏ•
  • ็”Ÿๅ‘ฝๅ‘จๆœŸ๏ผŸ๏ผŸ
  • cli???
You might also like...

Convert some JavaScript/TypeScript code string into a .d.ts TypeScript Declaration code string

convert-to-dts Converts the source code for any .js or .ts file into the equivalent .d.ts code TypeScript would generate. Usage import { convertToDecl

Mar 3, 2022

AnonCrypt ciphers and diciphers your messages or strings which makes you send texts to people without them understanding it.

AnonCrypt ciphers and diciphers your messages or strings which makes you send texts to people without them understanding it.

AnonCrypt ciphers and diciphers your messages or strings which makes you send texts to people without them understanding it. Anoncrypt uses Aes192 cipher encryption type and not Hmac.

Oct 23, 2022

simple JavaScript library to animate texts

simple JavaScript library to animate texts

Animated Texts Hi, this library is a simple javascript text animator Properties force type: number default: 300 start_delay_time type: number default:

Jan 11, 2022

Shuffle texts.

shuffleText This is JavaScript file. When mouse over element shuffle texts in html. It is easy to use it for everyone. Update Infomation If you make s

Apr 5, 2022

A simple code that creates a string of random characters displayed in an html object, all saving in a json file.

A simple code that creates a string of random characters displayed in an html object, all saving in a json file.

I'm 17 Years Old Developer / Lead Developer. ๐Ÿ’ป I'm wroking on AdrenalinaRP, GrandRDM. ๐Ÿช™ Iโ€™m currently learning JavaScript. ๐Ÿซ‚ Iโ€™m looking to collabo

Nov 17, 2022

A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM deffiniation and appropriate file structure.

Welcome to function-stencil ๐Ÿ‘‹ A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM

Jun 20, 2022

Serve file server with single zip file as file system in Deno.

zipland Serve file server with one-single zip file in Deno. Support zip just zip32 with deflated or uncompressed serving plaintext deflate Examples Yo

Nov 2, 2022

Feel free to create new file, don't hesitate to pull your code, the most important thing is that the file name here must match your nickname so that file does not conflict with other people.

Hacktoberfest Indonesia Apa Itu Hacktoberfest ? Hacktoberfest adalah acara tahunan yang bertujuan untuk mendorong berkontribusi kedalam ekosistem open

Dec 15, 2022

This package generates a unique ID/String for different browsers. Like chrome, Firefox and any other browsers which supports canvas and audio Fingerprinting.

This package generates a unique ID/String for different browsers. Like chrome, Firefox and any other browsers which supports canvas and audio Fingerprinting.

Broprint.js The world's easiest, smallest and powerful visitor identifier for browsers. This package generates a unique ID/String for different browse

Dec 25, 2022

Little Javascript / Typescript library for validating format of string like email, url, password...

String-Validators Little Javascript / Typescript library for validating format of string like email, url, password... Signaler un Bug ยท Proposer une F

Oct 14, 2022

A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

Apr 6, 2022

A work-in-progress HTML sanitizer that strives for: performance like window.Sanitizer, readiness like DOMPurify, and ability to run in a WebWorker like neither of those.

Amuchina A work-in-progress HTML sanitizer that strives for: performance like window.Sanitizer, readiness like DOMPurify, and ability to run in a WebW

Sep 17, 2022

With this File Manager prepared for PHP/Js, you can perform all file operations on your server without any problems.

FileManager With this File Manager prepared for PHP/Js, you can perform all file operations on your server without any problems. Instead of downloadin

Sep 23, 2022

String validation

validator.js A library of string validators and sanitizers. Strings only This library validates and sanitizes strings only. If you're not sure if your

Jan 5, 2023

The ultimate JavaScript string library

The ultimate JavaScript string library

Voca is a JavaScript library for manipulating strings. https://vocajs.com v.camelCase('bird flight'); // = 'birdFlight' v.sprintf('%s co

Dec 20, 2022

String manipulation helpers for javascript

The stable release documentation can be found here https://epeli.github.io/underscore.string/ Underscore.string Javascript lacks complete string manip

Dec 25, 2022

Extra JavaScript string methods.

string.js string.js, or simply S is a lightweight ( 5 kb minified and gzipped) JavaScript library for the browser or for Node.js that provides extra

Dec 17, 2022
Releases(1.0.0)
Owner
ๅ…”ๅญๅ…ˆ็”Ÿ
I'll be there for you.
ๅ…”ๅญๅ…ˆ็”Ÿ
String validation

validator.js A library of string validators and sanitizers. Strings only This library validates and sanitizes strings only. If you're not sure if your

null 20.7k Jan 5, 2023
A library for validate a string using regular expressions.

Fogex Form Regex Quickly and easily check if the content is valid. Installation npm install fogex or yarn add fogex Usage import fogex from 'fogex';

null 5 May 5, 2022
JQuery-TableToExcel - Light weight jQuery plugin for export HTML table to excel file

tableToExcel Light weight jQuery plugin for export table to excel file Demos Website and demo here: http://tanvirpro.com/all_project/jQueryTableToExce

Tanvir Sarker 4 May 8, 2022
๐Ÿฆฉ Joi like validations for TypeScript

?? Computed Types Runtime validation types for TypeScript. Computed-Types (formerly: Funval) is a strongly-typed validation library for TypeScript. Us

Neuledge 338 Jan 4, 2023
Jquery.iocurve - jQuery plugin like Tone Curve on Photoshop or GIMP

jquery.iocurve jQuery plugin like Tone Curve on Photoshop or GIMP. See Official page for more information. Quick start Create HTML and open in your br

null 5 Jul 28, 2022
Simple translation for your javascripts, yummy with your favorite templates engine like EJS.

jsperanto Simple translation for your javascripts, yummy with your favorite templates engine like EJS. Pluralization, interpolation & "nested lookup"

Jean-Philippe Joyal 62 Oct 21, 2021
What does the Cosmos Hub validator set looks like without ICF delegations?

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Made in Block 2 Sep 2, 2022
Helps to encode a string to base64 and decode a base64 string to a normal string.

@prashoonb/base64-encoder-decoder Installation npm install @prashoonb/base64-encoder-decoder API base64.encode(input) This function takes a byte strin

PrashoonB 4 Mar 29, 2022
Wordle clone but the words are replaced by STIB/MIVB stops

STIBle / MIVBle STIBle / MIVBle is a WorLdle clone, except that you don't guess a country, but a stop in the STIB's (Brussels' public transport compan

null 3 May 26, 2022
Moxiecode 5.6k Jan 1, 2023