@cjser/normalize-newline 5.0.0-cjser.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjser/index.cjs +47 -0
- package/index.d.ts +18 -0
- package/index.js +28 -0
- package/license +9 -0
- package/package.json +74 -0
- package/readme.md +46 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/@cjser/normalize-newline.tmp-26-1778153746895/index.js
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
default: () => normalizeNewline
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(index_exports);
|
|
25
|
+
var CRLF_REGEX = /\r\n/g;
|
|
26
|
+
var CARRIAGE_RETURN = 13;
|
|
27
|
+
var LINE_FEED = 10;
|
|
28
|
+
function normalizeNewline(input) {
|
|
29
|
+
if (typeof input === "string") {
|
|
30
|
+
return input.replaceAll(CRLF_REGEX, "\n");
|
|
31
|
+
}
|
|
32
|
+
if (input instanceof Uint8Array) {
|
|
33
|
+
const result = [];
|
|
34
|
+
let i = 0;
|
|
35
|
+
while (i < input.length) {
|
|
36
|
+
if (input[i] === CARRIAGE_RETURN && input[i + 1] === LINE_FEED) {
|
|
37
|
+
result.push(LINE_FEED);
|
|
38
|
+
i += 2;
|
|
39
|
+
} else {
|
|
40
|
+
result.push(input[i]);
|
|
41
|
+
i++;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return new Uint8Array(result);
|
|
45
|
+
}
|
|
46
|
+
throw new TypeError(`Expected a \`string\` or a \`Uint8Array\`, got \`${typeof input}\``);
|
|
47
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Normalizes CRLF (`\r\n`) to LF (`\n`). Other newline characters (`\r` or `\n` alone) are left unchanged.
|
|
3
|
+
|
|
4
|
+
@example
|
|
5
|
+
```
|
|
6
|
+
import normalizeNewline from '@cjser/normalize-newline';
|
|
7
|
+
|
|
8
|
+
normalizeNewline('foo\r\nbar\nbaz');
|
|
9
|
+
//=> 'foo\nbar\nbaz'
|
|
10
|
+
|
|
11
|
+
const uint8Array = new TextEncoder().encode('foo\r\nbar\nbaz');
|
|
12
|
+
const normalized = normalizeNewline(uint8Array);
|
|
13
|
+
new TextDecoder().decode(normalized);
|
|
14
|
+
//=> 'foo\nbar\nbaz'
|
|
15
|
+
```
|
|
16
|
+
*/
|
|
17
|
+
export default function normalizeNewline(input: string): string;
|
|
18
|
+
export default function normalizeNewline(input: Uint8Array): Uint8Array;
|
package/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const CRLF_REGEX = /\r\n/g;
|
|
2
|
+
const CARRIAGE_RETURN = 13; // \r
|
|
3
|
+
const LINE_FEED = 10; // \n
|
|
4
|
+
|
|
5
|
+
export default function normalizeNewline(input) {
|
|
6
|
+
if (typeof input === 'string') {
|
|
7
|
+
return input.replaceAll(CRLF_REGEX, '\n');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (input instanceof Uint8Array) {
|
|
11
|
+
const result = [];
|
|
12
|
+
let i = 0;
|
|
13
|
+
|
|
14
|
+
while (i < input.length) {
|
|
15
|
+
if (input[i] === CARRIAGE_RETURN && input[i + 1] === LINE_FEED) {
|
|
16
|
+
result.push(LINE_FEED);
|
|
17
|
+
i += 2;
|
|
18
|
+
} else {
|
|
19
|
+
result.push(input[i]);
|
|
20
|
+
i++;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return new Uint8Array(result);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
throw new TypeError(`Expected a \`string\` or a \`Uint8Array\`, got \`${typeof input}\``);
|
|
28
|
+
}
|
package/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cjser/normalize-newline",
|
|
3
|
+
"version": "5.0.0-cjser.2",
|
|
4
|
+
"description": "Normalize the newline characters in a string to `\\n`",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://code.moenext.com/3rdeye/cjser.git"
|
|
9
|
+
},
|
|
10
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Sindre Sorhus",
|
|
13
|
+
"email": "sindresorhus@gmail.com",
|
|
14
|
+
"url": "https://sindresorhus.com"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"require": "./dist-cjser/index.cjs",
|
|
20
|
+
"default": "./index.js"
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "xo && ava"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"index.js",
|
|
31
|
+
"index.d.ts",
|
|
32
|
+
"dist-cjser"
|
|
33
|
+
],
|
|
34
|
+
"keywords": [
|
|
35
|
+
"newline",
|
|
36
|
+
"linebreak",
|
|
37
|
+
"line",
|
|
38
|
+
"lf",
|
|
39
|
+
"crlf",
|
|
40
|
+
"eol",
|
|
41
|
+
"linefeed",
|
|
42
|
+
"character",
|
|
43
|
+
"char",
|
|
44
|
+
"normalize",
|
|
45
|
+
"convert",
|
|
46
|
+
"replace"
|
|
47
|
+
],
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"ava": "^6.4.1",
|
|
50
|
+
"xo": "^1.2.2"
|
|
51
|
+
},
|
|
52
|
+
"types": "./index.d.ts",
|
|
53
|
+
"main": "./dist-cjser/index.cjs",
|
|
54
|
+
"cjser": {
|
|
55
|
+
"sourceVersion": "5.0.0",
|
|
56
|
+
"cjserVersion": 2,
|
|
57
|
+
"original": {
|
|
58
|
+
"name": "normalize-newline",
|
|
59
|
+
"version": "5.0.0",
|
|
60
|
+
"exports": {
|
|
61
|
+
"types": "./index.d.ts",
|
|
62
|
+
"default": "./index.js"
|
|
63
|
+
},
|
|
64
|
+
"repository": "sindresorhus/normalize-newline",
|
|
65
|
+
"files": [
|
|
66
|
+
"index.js",
|
|
67
|
+
"index.d.ts"
|
|
68
|
+
],
|
|
69
|
+
"scripts": {
|
|
70
|
+
"test": "xo && ava"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# normalize-newline
|
|
2
|
+
|
|
3
|
+
> Normalize the [newline](https://en.wikipedia.org/wiki/Newline) characters in a string to `\n`
|
|
4
|
+
|
|
5
|
+
Converts Windows-style CRLF (`\r\n`) line endings to Unix-style LF (`\n`). Works in both Node.js and browsers.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install normalize-newline
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import normalizeNewline from 'normalize-newline';
|
|
17
|
+
|
|
18
|
+
normalizeNewline('foo\r\nbar\nbaz');
|
|
19
|
+
//=> 'foo\nbar\nbaz'
|
|
20
|
+
|
|
21
|
+
const uint8Array = new TextEncoder().encode('foo\r\nbar\nbaz');
|
|
22
|
+
const normalized = normalizeNewline(uint8Array);
|
|
23
|
+
new TextDecoder().decode(normalized);
|
|
24
|
+
//=> 'foo\nbar\nbaz'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API
|
|
28
|
+
|
|
29
|
+
### normalizeNewline(input)
|
|
30
|
+
|
|
31
|
+
Normalizes CRLF (`\r\n`) to LF (`\n`). Other newline characters (`\r` or `\n` alone) are left unchanged.
|
|
32
|
+
|
|
33
|
+
#### input
|
|
34
|
+
|
|
35
|
+
Type: `string | Uint8Array`
|
|
36
|
+
|
|
37
|
+
Input to normalize.
|
|
38
|
+
|
|
39
|
+
## Related
|
|
40
|
+
|
|
41
|
+
- [normalize-newline-cli](https://github.com/sindresorhus/normalize-newline-cli) - CLI for this module
|
|
42
|
+
|
|
43
|
+
## cjser
|
|
44
|
+
|
|
45
|
+
This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
|
|
46
|
+
Original repository: https://github.com/sindresorhus/normalize-newline
|