This commit is contained in:
2025-07-06 20:54:40 +08:00
parent f665eaab54
commit ced488a958
4076 changed files with 1108355 additions and 0 deletions

18
node_modules/strip-final-newline/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,18 @@
/**
Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from a string or Uint8Array.
@returns The input without any final newline.
@example
```
import stripFinalNewline from 'strip-final-newline';
stripFinalNewline('foo\nbar\n\n');
//=> 'foo\nbar\n'
const uint8Array = new TextEncoder().encode('foo\nbar\n\n')
new TextDecoder().decode(stripFinalNewline(uint8Array));
//=> 'foo\nbar\n'
```
*/
export default function stripFinalNewline<T extends string | Uint8Array>(input: T): T;

26
node_modules/strip-final-newline/index.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
export default function stripFinalNewline(input) {
if (typeof input === 'string') {
return stripFinalNewlineString(input);
}
if (!(ArrayBuffer.isView(input) && input.BYTES_PER_ELEMENT === 1)) {
throw new Error('Input must be a string or a Uint8Array');
}
return stripFinalNewlineBinary(input);
}
const stripFinalNewlineString = input =>
input.at(-1) === LF
? input.slice(0, input.at(-2) === CR ? -2 : -1)
: input;
const stripFinalNewlineBinary = input =>
input.at(-1) === LF_BINARY
? input.subarray(0, input.at(-2) === CR_BINARY ? -2 : -1)
: input;
const LF = '\n';
const LF_BINARY = LF.codePointAt(0);
const CR = '\r';
const CR_BINARY = CR.codePointAt(0);

9
node_modules/strip-final-newline/license generated vendored Normal file
View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.

49
node_modules/strip-final-newline/package.json generated vendored Normal file
View File

@@ -0,0 +1,49 @@
{
"name": "strip-final-newline",
"version": "4.0.0",
"description": "Strip the final newline character from a string or Uint8Array",
"license": "MIT",
"repository": "sindresorhus/strip-final-newline",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": ">=18"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"strip",
"trim",
"remove",
"delete",
"final",
"last",
"end",
"file",
"newline",
"linebreak",
"character",
"string",
"uint8array"
],
"devDependencies": {
"ava": "^6.0.1",
"tsd": "^0.29.0",
"xo": "^0.56.0"
}
}

34
node_modules/strip-final-newline/readme.md generated vendored Normal file
View File

@@ -0,0 +1,34 @@
# strip-final-newline
> Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from a string or Uint8Array.
This can be useful when parsing the output of, for example, `ChildProcess#execFile()`, as [binaries usually output a newline at the end](https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline). You cannot use `stdout.trimEnd()` for this as it removes all trailing newlines and whitespaces at the end.
## Install
```sh
npm install strip-final-newline
```
## Usage
```js
import stripFinalNewline from 'strip-final-newline';
stripFinalNewline('foo\nbar\n\n');
//=> 'foo\nbar\n'
const uint8Array = new TextEncoder().encode('foo\nbar\n\n')
new TextDecoder().decode(stripFinalNewline(uint8Array));
//=> 'foo\nbar\n'
```
## Performance
When using an `Uint8Array`, the original value is referenced, not copied. This is much more efficient, requires almost no memory, and remains milliseconds fast even on very large inputs.
If you'd like to ensure that modifying the return value does not also modify the value passed as input, please use `.slice()`.
```js
const value = new TextDecoder().decode(stripFinalNewline(uint8Array).slice());
```