@handy-common-utils/fs-utils
Advanced tools
Comparing version 1.0.1 to 1.0.5
@@ -50,6 +50,2 @@ /// <reference types="node" /> | ||
} | ||
/** | ||
* @namespace | ||
* @borrows FsUtils.escapeRegExpReplacement as escapeRegExpReplacement | ||
*/ | ||
export declare const escapeRegExpReplacement: typeof FsUtils.escapeRegExpReplacement; | ||
@@ -56,0 +52,0 @@ export declare const changeFileContent: typeof FsUtils.changeFileContent; |
@@ -71,6 +71,2 @@ "use strict"; | ||
exports.FsUtils = FsUtils; | ||
/** | ||
* @namespace | ||
* @borrows FsUtils.escapeRegExpReplacement as escapeRegExpReplacement | ||
*/ | ||
exports.escapeRegExpReplacement = FsUtils.escapeRegExpReplacement; | ||
@@ -77,0 +73,0 @@ exports.changeFileContent = FsUtils.changeFileContent; |
{ | ||
"name": "@handy-common-utils/fs-utils", | ||
"version": "1.0.1", | ||
"version": "1.0.5", | ||
"description": "File system operations related utilities based on fs-extra", | ||
"scripts": { | ||
"test": "nyc mocha -r ts-node/register test/**/*spec.ts", | ||
"prepare": "shx rm -rf dist && tsc && shx chmod +x dist/bin/*.js" | ||
"prepare": "shx rm -rf dist && tsc && shx chmod +x dist/bin/*.js", | ||
"preversion": "generate-api-docs-and-update-readme && git add README.md" | ||
}, | ||
@@ -23,3 +24,3 @@ "files": [ | ||
"devDependencies": { | ||
"@handy-common-utils/dev-dependencies": "^1.0.0", | ||
"@handy-common-utils/dev-dependencies": "^1.0.2", | ||
"@types/fs-extra": "^9.0.2", | ||
@@ -26,0 +27,0 @@ "@types/tmp": "^0.2.0", |
213
README.md
@@ -27,3 +27,212 @@ # @handy-common-utils/fs-utils | ||
<!-- API start--> | ||
<!-- API end--> | ||
<!-- API start --> | ||
<a name="readmemd"></a> | ||
**[@handy-common-utils/fs-utils](#readmemd)** | ||
> Globals | ||
## @handy-common-utils/fs-utils | ||
### Index | ||
#### Classes | ||
* [FsUtils](#classesfsutilsmd) | ||
#### Variables | ||
* [addSurroundingInFile](#addsurroundinginfile) | ||
* [afterString](#afterstring) | ||
* [beforeString](#beforestring) | ||
* [changeFileContent](#changefilecontent) | ||
* [contentFilePath](#contentfilepath) | ||
* [escapeRegExpReplacement](#escaperegexpreplacement) | ||
* [filePath](#filepath) | ||
* [matchPattern](#matchpattern) | ||
* [replaceInFile](#replaceinfile) | ||
* [replaceInFileWithFileContent](#replaceinfilewithfilecontent) | ||
### Variables | ||
#### addSurroundingInFile | ||
• `Const` **addSurroundingInFile**: [addSurroundingInFile](#addsurroundinginfile) = FsUtils.addSurroundingInFile | ||
___ | ||
#### afterString | ||
• **afterString**: string | ||
___ | ||
#### beforeString | ||
• **beforeString**: string | ||
___ | ||
#### changeFileContent | ||
• `Const` **changeFileContent**: [changeFileContent](#changefilecontent) = FsUtils.changeFileContent | ||
___ | ||
#### contentFilePath | ||
• **contentFilePath**: string | ||
___ | ||
#### escapeRegExpReplacement | ||
• `Const` **escapeRegExpReplacement**: [escapeRegExpReplacement](#escaperegexpreplacement) = FsUtils.escapeRegExpReplacement | ||
___ | ||
#### filePath | ||
• **filePath**: string | ||
___ | ||
#### matchPattern | ||
• **matchPattern**: string | ||
___ | ||
#### replaceInFile | ||
• `Const` **replaceInFile**: [replaceInFile](#replaceinfile) = FsUtils.replaceInFile | ||
___ | ||
#### replaceInFileWithFileContent | ||
• `Const` **replaceInFileWithFileContent**: [replaceInFileWithFileContent](#replaceinfilewithfilecontent) = FsUtils.replaceInFileWithFileContent | ||
## Classes | ||
<a name="classesfsutilsmd"></a> | ||
**[@handy-common-utils/fs-utils](#readmemd)** | ||
> [Globals](#readmemd) / FsUtils | ||
### Class: FsUtils | ||
#### Hierarchy | ||
* **FsUtils** | ||
#### Index | ||
##### Methods | ||
* [addSurroundingInFile](#addsurroundinginfile) | ||
* [changeFileContent](#changefilecontent) | ||
* [escapeRegExpReplacement](#escaperegexpreplacement) | ||
* [replaceInFile](#replaceinfile) | ||
* [replaceInFileWithFileContent](#replaceinfilewithfilecontent) | ||
#### Methods | ||
##### addSurroundingInFile | ||
▸ `Static` **addSurroundingInFile**(`filePath`: string, `matchPattern`: RegExp, `addBefore`: string, `addAfter`: string, `fileEncoding?`: Parameters\<Buffer[\"toString\"]>[\"0\"]): Promise\<void> | ||
Add surrounding content to the matching sections in the text file. | ||
###### Parameters: | ||
Name | Type | Default value | Description | | ||
------ | ------ | ------ | ------ | | ||
`filePath` | string | - | path to the file | | ||
`matchPattern` | RegExp | - | RegExp for deciding which section of the file would be processed. You must have a capturing group in the pattern. You may want to use these tricks: `m` flag, `g` flag, `[\s\S]*`, `.*?` | | ||
`addBefore` | string | - | the string to be added before the capturing group, no need to escape anything | | ||
`addAfter` | string | - | the string to be added before the capturing group, no need to escape anything | | ||
`fileEncoding` | Parameters\<Buffer[\"toString\"]>[\"0\"] | "utf-8" | encoding of the file | | ||
**Returns:** Promise\<void> | ||
___ | ||
##### changeFileContent | ||
▸ `Static` **changeFileContent**(`filePath`: string, `transformContent`: (originalContent: string, filePath: string) => string \| PromiseLike\<string>, `fileEncoding?`: Parameters\<Buffer[\"toString\"]>[\"0\"]): Promise\<void> | ||
Change the text file content. | ||
This function loads the full content of the file into memory as string, so that it is not suitable for huge (for example, > 500MB) files. | ||
If the new content and original content are the same, the file won't be touched. | ||
###### Parameters: | ||
Name | Type | Default value | Description | | ||
------ | ------ | ------ | ------ | | ||
`filePath` | string | - | path to the file | | ||
`transformContent` | (originalContent: string, filePath: string) => string \| PromiseLike\<string> | - | function for getting the new file content | | ||
`fileEncoding` | Parameters\<Buffer[\"toString\"]>[\"0\"] | "utf-8" | encoding of the file | | ||
**Returns:** Promise\<void> | ||
___ | ||
##### escapeRegExpReplacement | ||
▸ `Static` **escapeRegExpReplacement**(`input`: string): string | ||
Escape the ' | ||
sign in the string for using the string as the second argument to String.replace(...) | ||
###### Parameters: | ||
Name | Type | Description | | ||
------ | ------ | ------ | | ||
`input` | string | the original string | | ||
**Returns:** string | ||
a new string with all ' | ||
in the original string being replaced by '$' | ||
___ | ||
##### replaceInFile | ||
▸ `Static` **replaceInFile**(`filePath`: string, `matchPattern`: RegExp, `replacementOrBuilder`: string \| (matchPattern: RegExp, filePath: string) => string \| PromiseLike\<string>, `fileEncoding?`: Parameters\<Buffer[\"toString\"]>[\"0\"]): Promise\<void> | ||
Replace the matching sections in the text file. | ||
###### Parameters: | ||
Name | Type | Default value | Description | | ||
------ | ------ | ------ | ------ | | ||
`filePath` | string | - | path to the file | | ||
`matchPattern` | RegExp | - | RegExp for deciding which section of the file would be replaced. You may want to use these tricks: `m` flag, `g` flag, `[\s\S]*`, `.*?` | | ||
`replacementOrBuilder` | string \| (matchPattern: RegExp, filePath: string) => string \| PromiseLike\<string> | - | The replacement string or a function for building the replacement string. Please note that you can use special replacement patterns but also you need to take care of the escaping. For details of special replacement patterns see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace | | ||
`fileEncoding` | Parameters\<Buffer[\"toString\"]>[\"0\"] | "utf-8" | encoding of the file | | ||
**Returns:** Promise\<void> | ||
___ | ||
##### replaceInFileWithFileContent | ||
▸ `Static` **replaceInFileWithFileContent**(`filePath`: string, `matchPattern`: RegExp, `contentFilePath`: string, `fileEncoding?`: Parameters\<Buffer[\"toString\"]>[\"0\"]): Promise\<void> | ||
Replace the matching sections in the text file with content from another file. | ||
###### Parameters: | ||
Name | Type | Default value | Description | | ||
------ | ------ | ------ | ------ | | ||
`filePath` | string | - | path of the file | | ||
`matchPattern` | RegExp | - | RegExp for deciding which section of the file would be replaced. You must have a capturing group in the pattern. You may want to use these tricks: `m` flag, `g` flag, `[\s\S]*`, `.*?` | | ||
`contentFilePath` | string | - | path of the file for getting the replacement content | | ||
`fileEncoding` | Parameters\<Buffer[\"toString\"]>[\"0\"] | "utf-8" | encoding of the files | | ||
**Returns:** Promise\<void> | ||
<!-- API end --> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
31251
238
0
146