{"id":15743903,"url":"https://github.com/jonschlinkert/file-normalize","last_synced_at":"2025-10-13T13:32:21.944Z","repository":{"id":17812675,"uuid":"20706241","full_name":"jonschlinkert/file-normalize","owner":"jonschlinkert","description":"File system utils for normalizing things like eol, encoding and BOM.","archived":false,"fork":false,"pushed_at":"2017-08-01T16:42:16.000Z","size":19,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-06T22:07:30.847Z","etag":null,"topics":["bom","buffer","eol","file","javascript","newline","nodejs","string"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-11T00:10:00.000Z","updated_at":"2021-04-12T22:29:16.000Z","dependencies_parsed_at":"2022-09-02T12:25:36.346Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/file-normalize","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/jonschlinkert/file-normalize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Ffile-normalize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Ffile-normalize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Ffile-normalize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Ffile-normalize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/file-normalize/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Ffile-normalize/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261088343,"owners_count":23107678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bom","buffer","eol","file","javascript","newline","nodejs","string"],"created_at":"2024-10-04T03:21:57.687Z","updated_at":"2025-10-13T13:32:16.902Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# file-normalize [![NPM version](https://img.shields.io/npm/v/file-normalize.svg?style=flat)](https://www.npmjs.com/package/file-normalize) [![NPM monthly downloads](https://img.shields.io/npm/dm/file-normalize.svg?style=flat)](https://npmjs.org/package/file-normalize)  [![NPM total downloads](https://img.shields.io/npm/dt/file-normalize.svg?style=flat)](https://npmjs.org/package/file-normalize) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/file-normalize.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/file-normalize) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/file-normalize.svg?style=flat\u0026label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/file-normalize)\n\n\u003e File system utils for normalizing things like eol, encoding and BOM.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save file-normalize\n```\n\nInstall with [yarn](https://yarnpkg.com):\n\n```sh\n$ yarn add file-normalize\n```\n\n## API\n\n### [.normalizeSlash](index.js#L37)\n\nNormalize 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.\n\n**Params**\n\n* `filepath` **{String}**\n* `returns` **{String}**\n\n**Example**\n\n```js\nvar file = require('file-normalize');\nconsole.log(file.normalizeSlash('foo\\\\bar'));\n//=\u003e 'foo/bar'\n```\n\n### [.normalizeEOL](index.js#L59)\n\nNormalize line endings to use the given `eol` character, or the defaults of the current operating system.\n\n**Params**\n\n* `str` **{String}**\n* `returns` **{String}**\n\n**Example**\n\n```js\nvar fs = require('fs');\nvar file = require('file-normalize');\nvar str = fs.readFileSync('foo.txt', 'utf8');\nconsole.log(file.normalizeEOL(str));\n```\n\n### [.normalizeNL](index.js#L80)\n\nNormalize all line endings to unix newlines (strips carriage returns).\n\n**Params**\n\n* `str` **{String}**\n* `returns` **{String}**\n\n**Example**\n\n```js\nvar fs = require('fs');\nvar file = require('file-normalize');\nvar str = fs.readFileSync('foo.txt', 'utf8');\nconsole.log(file.normalizeNL(str));\n```\n\n### [.stripBOM](index.js#L101)\n\nStrip byte-order marks.\n\n**Params**\n\n* `val` **{String|Buffer}**\n* `returns` **{String}**\n\n**Example**\n\n```js\nvar fs = require('fs');\nvar file = require('file-normalize');\nvar str = file.readFileSync('foo.txt', 'utf8');\nconsole.log(file.stripBOM(str));\n```\n\n### [.append](index.js#L141)\n\nAppend a string or buffer to another string or buffer ensuring to preserve line ending characters.\n\n**Params**\n\n* `prefix` **{String|Buffer}**: String or Buffer that will be used to check for an existing line ending. The suffix is appended to this.\n* `suffix` **{String|Buffer}**: String or Buffer that will be appended to the prefix.\n* `returns` **{String|Buffer}**: Final String or Buffer\n\n**Example**\n\n```js\nconsole.log([append(new Buffer('abc\\r\\n'), new Buffer('def')).toString()]);\n//=\u003e [ 'abc\\r\\ndef\\r\\n' ]\n\nconsole.log([append(new Buffer('abc\\n'), new Buffer('def')).toString()]);\n//=\u003e [ 'abc\\ndef\\n' ]\n\n// uses os.EOL when a line ending is not found\nconsole.log([append(new Buffer('abc'), new Buffer('def')).toString()]);\n//=\u003e [ 'abc\\ndef' ]\n\nconsole.log([append('abc\\r\\n', 'def')]);\n//=\u003e [ 'abc\\r\\ndef\\r\\n' ]\n\nconsole.log([append('abc\\n', 'def')]);\n//=\u003e [ 'abc\\ndef\\n' ]\n\n// uses os.EOL when a line ending is not found\nconsole.log([append('abc', 'def')]);\n//=\u003e [ 'abc\\ndef' ]\n```\n\n### [.appendString](index.js#L168)\n\nAppend a string to another string ensuring to preserve line ending characters.\n\n**Params**\n\n* `str` **{String}**: String that will be used to check for an existing line ending. The suffix is appended to this.\n* `suffix` **{String}**: String that will be appended to the str.\n* `returns` **{String}**: Final String\n\n**Example**\n\n```js\nconsole.log([appendString('abc\\r\\n', 'def')]);\n//=\u003e [ 'abc\\r\\ndef\\r\\n' ]\n\nconsole.log([appendString('abc\\n', 'def')]);\n//=\u003e [ 'abc\\ndef\\n' ]\n\n// uses os.EOL when a line ending is not found\nconsole.log([appendString('abc', 'def')]);\n//=\u003e [ 'abc\\ndef' ]\n```\n\n### [.appendBuffer](index.js#L190)\n\nAppend a buffer to another buffer ensuring to preserve line ending characters.\n\n**Params**\n\n* `buf` **{Buffer}**: Buffer that will be used to check for an existing line ending. The suffix is appended to this.\n* `suffix` **{Buffer}**: Buffer that will be appended to the buf.\n* `returns` **{Buffer}**: Final Buffer\n\n**Example**\n\n```js\nconsole.log([appendBuffer(new Buffer('abc\\r\\n'), new Buffer('def')).toString()]);\n//=\u003e [ 'abc\\r\\ndef\\r\\n' ]\n\nconsole.log([appendBuffer(new Buffer('abc\\n'), new Buffer('def')).toString()]);\n//=\u003e [ 'abc\\ndef\\n' ]\n\n// uses os.EOL when a line ending is not found\nconsole.log([appendBuffer(new Buffer('abc'), new Buffer('def')).toString()]);\n//=\u003e [ 'abc\\ndef' ]\n```\n\n## About\n\n### Related projects\n\n* [fs-utils](https://www.npmjs.com/package/fs-utils): fs extras and utilities to extend the node.js file system module. Used in Assemble and… [more](https://github.com/assemble/fs-utils) | [homepage](https://github.com/assemble/fs-utils \"fs extras and utilities to extend the node.js file system module. Used in Assemble and many other projects.\")\n* [normalize-path](https://www.npmjs.com/package/normalize-path): Normalize file path slashes to be unix-like forward slashes. Also condenses repeat slashes to a… [more](https://github.com/jonschlinkert/normalize-path) | [homepage](https://github.com/jonschlinkert/normalize-path \"Normalize file path slashes to be unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes unless disabled.\")\n* [parse-filepath](https://www.npmjs.com/package/parse-filepath): Pollyfill for node.js `path.parse`, parses a filepath into an object. | [homepage](https://github.com/jonschlinkert/parse-filepath \"Pollyfill for node.js `path.parse`, parses a filepath into an object.\")\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 15 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 6  | [doowb](https://github.com/doowb) |  \n| 1  | [phated](https://github.com/phated) |  \n\n### Building docs\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n### Running tests\n\nRunning 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:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n### Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 01, 2017._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Ffile-normalize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Ffile-normalize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Ffile-normalize/lists"}