File system utils for normalizing things like eol, encoding and BOM.
npm install file-normalize> File system utils for normalizing things like eol, encoding and BOM.
Install with npm:
``sh`
$ npm install --save file-normalize
Install with yarn:
`sh`
$ yarn add file-normalize
Normalize slashes in the given filepath to forward slashes. Note that this is a simple replacement of \\ with /, and this method does not check for URL or windows drive characters.
Params
* filepath {String}returns
* {String}
Example
`js`
var file = require('file-normalize');
console.log(file.normalizeSlash('foo\\bar'));
//=> 'foo/bar'
Normalize line endings to use the given eol character, or the defaults of the current operating system.
Params
* str {String}returns
* {String}
Example
`js`
var fs = require('fs');
var file = require('file-normalize');
var str = fs.readFileSync('foo.txt', 'utf8');
console.log(file.normalizeEOL(str));
Normalize all line endings to unix newlines (strips carriage returns).
Params
* str {String}returns
* {String}
Example
`js`
var fs = require('fs');
var file = require('file-normalize');
var str = fs.readFileSync('foo.txt', 'utf8');
console.log(file.normalizeNL(str));
Strip byte-order marks.
Params
* val {String|Buffer}returns
* {String}
Example
`js`
var fs = require('fs');
var file = require('file-normalize');
var str = file.readFileSync('foo.txt', 'utf8');
console.log(file.stripBOM(str));
Append a string or buffer to another string or buffer ensuring to preserve line ending characters.
Params
* prefix {String|Buffer}: String or Buffer that will be used to check for an existing line ending. The suffix is appended to this.suffix
* {String|Buffer}: String or Buffer that will be appended to the prefix.returns
* {String|Buffer}: Final String or Buffer
Example
`js
console.log([append(new Buffer('abc\r\n'), new Buffer('def')).toString()]);
//=> [ 'abc\r\ndef\r\n' ]
console.log([append(new Buffer('abc\n'), new Buffer('def')).toString()]);
//=> [ 'abc\ndef\n' ]
// uses os.EOL when a line ending is not found
console.log([append(new Buffer('abc'), new Buffer('def')).toString()]);
//=> [ 'abc\ndef' ]
console.log([append('abc\r\n', 'def')]);
//=> [ 'abc\r\ndef\r\n' ]
console.log([append('abc\n', 'def')]);
//=> [ 'abc\ndef\n' ]
// uses os.EOL when a line ending is not found
console.log([append('abc', 'def')]);
//=> [ 'abc\ndef' ]
`
Append a string to another string ensuring to preserve line ending characters.
Params
* str {String}: String that will be used to check for an existing line ending. The suffix is appended to this.suffix
* {String}: String that will be appended to the str.returns
* {String}: Final String
Example
`js
console.log([appendString('abc\r\n', 'def')]);
//=> [ 'abc\r\ndef\r\n' ]
console.log([appendString('abc\n', 'def')]);
//=> [ 'abc\ndef\n' ]
// uses os.EOL when a line ending is not found
console.log([appendString('abc', 'def')]);
//=> [ 'abc\ndef' ]
`
Append a buffer to another buffer ensuring to preserve line ending characters.
Params
* buf {Buffer}: Buffer that will be used to check for an existing line ending. The suffix is appended to this.suffix
* {Buffer}: Buffer that will be appended to the buf.returns
* {Buffer}: Final Buffer
Example
`js
console.log([appendBuffer(new Buffer('abc\r\n'), new Buffer('def')).toString()]);
//=> [ 'abc\r\ndef\r\n' ]
console.log([appendBuffer(new Buffer('abc\n'), new Buffer('def')).toString()]);
//=> [ 'abc\ndef\n' ]
// uses os.EOL when a line ending is not found
console.log([appendBuffer(new Buffer('abc'), new Buffer('def')).toString()]);
//=> [ 'abc\ndef' ]
`
* fs-utils: fs extras and utilities to extend the node.js file system module. Used in Assemble and… more | homepage
* normalize-path: Normalize file path slashes to be unix-like forward slashes. Also condenses repeat slashes to a… more | homepage
* parse-filepath: Pollyfill for node.js path.parse, parses a filepath into an object. | path.parse, parses a filepath into an object."" class="text-primary hover:underline" target="_blank" rel="noopener noreferrer">homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
| Commits | Contributor |
| --- | --- |
| 15 | jonschlinkert |
| 6 | doowb |
| 1 | phated |
_(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)_
To generate the readme, run the following command:
`sh`
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
`sh``
$ npm install && npm test
Jon Schlinkert
* github/jonschlinkert
* twitter/jonschlinkert
Copyright © 2017, Jon Schlinkert.
Released under the MIT License.
*
_This file was generated by verb-generate-readme, v0.6.0, on August 01, 2017._