tiny replace string/regex in files.
npm install tiny-replace-files
Like vscode, simple utility to quickly replace text in one or more files.
!Travis (.org)
!npm bundle size
!npm



``shnpm
npm install --save tiny-replace-files fast-glob
$3
#### Sync
`ts
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`ts
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)
})
`$3
#### Replace a single file or glob
`ts
const options = {
files: 'file',
};
`#### Replace multiple files or globs
`ts
const options = {
files: [
'file1',
'file2',
'file3',
],
};const options = {
files: [
'file1',
'file2/**',
]
};
`#### Replace by regex
`ts
const options = {
from: /foo/g,
to: 'bar',
};
`####
from callback`ts
const options = {
files: 'file',
from: (file) => new RegExp(file, 'g'),
to: 'bar',
};
`####
to callback`ts
const options = {
files: './ques2.md',
from: 'quest 2',
to: (match: string) => match.toUpperCase(),
countMatches: true
}
`#### Ignore file(s) or glob
`ts
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.
`ts
const options = {
disableGlobs: true,
};
`####
glob configurationAPI passed to the fast-glob:
`ts
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.
`ts
const options = {
encoding: 'utf8',
};
`####
freeze Runfreeze mode will do not replace & change, just run the process.
`ts
const options = {
freeze: true,
};
``See CHANGELOG.
- [x] init lib
- [x] 完成 replaceStringInFiles 函数开发
- [x] 完成同步函数开发
- [x] 完成测试
- [ ] 生命周期??
- [ ] cli???