Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@handy-common-utils/fs-utils

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@handy-common-utils/fs-utils - npm Package Compare versions

Comparing version 1.0.1 to 1.0.5

4

dist/fs-utils.d.ts

@@ -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;

7

package.json
{
"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",

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc