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

file-normalize

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-normalize

File system utils for normalizing things like eol, encoding and BOM.

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
94
increased by38.24%
Maintainers
3
Weekly downloads
 
Created
Source

file-normalize NPM version NPM monthly downloads NPM total downloads Linux Build Status Windows Build Status

File system utils for normalizing things like eol, encoding and BOM.

Install

Install with npm:

$ npm install --save file-normalize

Install with yarn:

$ yarn add file-normalize

API

.normalizeSlash

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

var file = require('file-normalize');
console.log(file.normalizeSlash('foo\\bar'));
//=> 'foo/bar'

.normalizeEOL

Normalize line endings to use the given eol character, or the defaults of the current operating system.

Params

  • str {String}
  • returns {String}

Example

var fs = require('fs');
var file = require('file-normalize');
var str = fs.readFileSync('foo.txt', 'utf8');
console.log(file.normalizeEOL(str));

.normalizeNL

Normalize all line endings to unix newlines (strips carriage returns).

Params

  • str {String}
  • returns {String}

Example

var fs = require('fs');
var file = require('file-normalize');
var str = fs.readFileSync('foo.txt', 'utf8');
console.log(file.normalizeNL(str));

.stripBOM

Strip byte-order marks.

Params

  • val {String|Buffer}
  • returns {String}

Example

var fs = require('fs');
var file = require('file-normalize');
var str = file.readFileSync('foo.txt', 'utf8');
console.log(file.stripBOM(str));

.append

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

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' ]

.appendString

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

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' ]

.appendBuffer

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

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' ]

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

CommitsContributor
15jonschlinkert
6doowb
1phated

Building docs

(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:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

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:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on August 01, 2017.

Keywords

FAQs

Package last updated on 01 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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