Section Manager
Lightweight section management of Files. Wraps section-manager
.
Installation
npm install file-section-manager
, oryarn add file-section-manager
Example
fileSectionManager.findAndUpdateSection'MySection', updatedSection fileSectionManager.writeSync // This will write to the file on disk console.logfileSectionManager.toString
/* OutputHelloWorld! <-- MySection OneTwoThree --> MySection Bye!*/
API
- This module primarily exports
FileSectionManager
- This module also re-exports all exports of
SectionManager
FileSectionManager
FileSectionManagerabsolutePathFileName: string, options: SectionManagerOptions: FileSectionManager
padding
: controls whether or not there should be a new line after the section start and before the section end- This setting can be overridden on the update methods
sectionSyntax
: gives the developer control over the syntax for delimiting each section- Defaults:
- start:
(name) => `<-- ${ name }`
- end:
(name) => `--> ${ name }`
- start:
- Defaults:
Methods
findAndUpdateSection
findAndUpdateSectionsection: string, sectionContentArray: string, padding?: boolean: void
prependToSection
prependToSectionsection: string, sectionContentArray: string: void
appendToSection
appendToSectionsection: string, sectionContentArray: string: void
toString
toString: string
The following are internal methods, but are exposed for cases that require manual control
findSection
findSectionsection: string:
updateSection
updateSectionoptions: UpdateSectionOptions: void
setFileArray
setFileArrayfileArray: string: void
getFileArray
getFileArray: string
Extending
You can extend the behavior by extending the base class SectionManager
. For example, this module does just that: