deploy: v0.12 fix 存档key名

This commit is contained in:
2026-06-24 03:09:02 +00:00
parent 7a08d49fe3
commit e0a5281119
58743 changed files with 7297269 additions and 39505 deletions
+19
View File
@@ -0,0 +1,19 @@
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- run: npm ci
- run: npm test
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Lukas Geiger
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.
+20
View File
@@ -0,0 +1,20 @@
# escape-carriage
[![Build Status](https://travis-ci.org/lgeiger/escape-carriage.svg?branch=master)](https://travis-ci.org/lgeiger/escape-carriage) [![Greenkeeper badge](https://badges.greenkeeper.io/lgeiger/escape-carriage.svg)](https://greenkeeper.io/)
Escape `\r` the right way.
```
npm install --save escape-carriage
```
## Usage
```javascript
var escapeCarriageReturn = require('escape-carriage');
escapeCarriageReturn('This sentence\rThat\nwill make you pause.');
// That sentence
// will make you pause.
```
+13
View File
@@ -0,0 +1,13 @@
/**
* Escape carrigage returns like a terminal
*/
export function escapeCarriageReturn(text: string): string;
export default escapeCarriageReturn;
/**
* Safely escape carrigage returns like a terminal.
* This allows to escape carrigage returns while allowing future output to be appended
* without loosing information.
* Use this as a intermediate escape step if your stream hasn't completed yet.
*/
export function escapeCarriageReturnSafe(text: string): string;
+66
View File
@@ -0,0 +1,66 @@
/**
* Escape carrigage returns like a terminal
* @param {string} txt - String to escape.
* @return {string} - Escaped string.
*/
function escapeCarriageReturn(txt) {
if (!txt) return "";
if (!/\r/.test(txt)) return txt;
txt = txt.replace(/\r+\n/gm, "\n"); // \r followed by \n --> newline
while (/\r./.test(txt)) {
txt = txt.replace(/^([^\r\n]*)\r+([^\r\n]+)/gm, function (_, base, insert) {
return insert + base.slice(insert.length);
});
}
return txt;
}
function findLongestString(arr) {
var longest = 0;
for (var i = 0; i < arr.length; i++) {
if (arr[longest].length <= arr[i].length) {
longest = i;
}
}
return longest;
}
function escapeSingleLineSafe(txt) {
if (!/\r/.test(txt)) return txt;
var arr = txt.split("\r");
var res = [];
while (arr.length > 0) {
var longest = findLongestString(arr);
res.push(arr[longest]);
arr = arr.slice(longest + 1);
}
return res.join("\r");
}
/**
* Safely escape carrigage returns like a terminal.
* This allows to escape carrigage returns while allowing future output to be appended
* without loosing information.
* Use this as a intermediate escape step if your stream hasn't completed yet.
* @param {string} txt - String to escape.
* @return {string} - Escaped string.
*/
function escapeCarriageReturnSafe(txt) {
if (!txt) return "";
if (!/\r/.test(txt)) return txt;
if (!/\n/.test(txt)) return escapeSingleLineSafe(txt);
txt = txt.replace(/\r+\n/gm, "\n"); // \r followed by \n --> newline
var idx = txt.lastIndexOf("\n");
return (
escapeCarriageReturn(txt.slice(0, idx)) +
"\n" +
escapeSingleLineSafe(txt.slice(idx + 1))
);
}
module.exports = escapeCarriageReturn;
module.exports.escapeCarriageReturn = escapeCarriageReturn;
module.exports.escapeCarriageReturnSafe = escapeCarriageReturnSafe;
+32
View File
@@ -0,0 +1,32 @@
{
"name": "escape-carriage",
"version": "1.3.1",
"description": "Escape carriage return the right way.",
"main": "index.js",
"types": "index.d.ts",
"directories": {
"test": "test"
},
"scripts": {
"test": "mocha test/index-spec.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/lgeiger/escape-carriage.git"
},
"keywords": [
"carriage",
"escape",
"return"
],
"author": "Lukas Geiger",
"license": "MIT",
"bugs": {
"url": "https://github.com/lgeiger/escape-carriage/issues"
},
"homepage": "https://github.com/lgeiger/escape-carriage#readme",
"devDependencies": {
"chai": "^4.3.7",
"mocha": "^10.2.0"
}
}
+46
View File
@@ -0,0 +1,46 @@
var escapeCarriageReturn = require('../index');
var carriageText = 'hasrn\r\nhasn\n\nabcdef\rhello\nab3\rx2\r\r1\r'.repeat(100);
var simpleText = 'That sentence will make you pause.\n'.repeat(5000);
// Timing code from https://github.com/nteract/nteract/blob/master/example-notebooks/immutable-revival.ipynb
[a, o, ms, s, log] = (function*() {
yield* [
process.hrtime(),
process.hrtime,
ms => (ms[0] * 1e9 + ms[1]) / 1000000,
s => s / 1000,
() => {
const f = o(a), msf = ms(f), sf = s(msf);
return { a, o: f, ms: msf, s: sf };
}
];
})();
// Calculate the milliseconds it takes to run f
function measure(f) {
start = log();
f();
end = log();
return end.ms - start.ms;
}
// measure the function run n times, return the mean
function runTrials(f, n = 10000) {
values = [];
for (var ii = 0; ii < n; ii++) {
values.push(measure(f));
}
return values.reduce((a, b) => a + b, 0) / n;
}
function carriageBenchmark() {
escapeCarriageReturn(carriageText);
}
function simpleBenchmark() {
escapeCarriageReturn(simpleText);
}
console.log('With carriage:', runTrials(carriageBenchmark));
console.log('Without carriage:', runTrials(simpleBenchmark));
+88
View File
@@ -0,0 +1,88 @@
var escapeCarriageReturn = require("../index");
var escapeCarriageReturnSafe = require("../index").escapeCarriageReturnSafe;
var expect = require("chai").expect;
describe("Escape carrigage return", function() {
it("can handle carrigage symbol", function() {
var txt = escapeCarriageReturn("This sentence\rThat\nwill make you pause.");
expect(txt).to.equal("That sentence\nwill make you pause.");
});
it("can handle carrigage symbol without new line", function() {
var txt = escapeCarriageReturn("1\r2\r3");
expect(txt).to.equal("3");
});
it("can handle complicated carrigage symbol", function() {
var input = [
"hasrn\r\n",
"hasn\n",
"\n",
"abcdef\r",
"hello\n",
"ab3\r",
"x2\r\r",
"1\r"
].join("");
var output = ["hasrn\n", "hasn\n", "\n", "hellof\n", "123\r"].join("");
expect(escapeCarriageReturn(input)).to.equal(output);
});
});
describe("Escape carrigage return safe", function() {
it("safely escapes multiline text", function() {
var txt = escapeCarriageReturnSafe(
"This sentence\rThat\nwill make you\r pause even longer."
);
expect(txt).to.equal("That sentence\n pause even longer.");
});
it("safely escapes multiline text", function() {
var txt = escapeCarriageReturnSafe(
"This sentence\rThat\nwill make you\r pause."
);
expect(txt).to.equal("That sentence\nwill make you\r pause.");
});
it("can safely handle complicated carrigage symbol", function() {
var input = [
"hasrn\r\n",
"hasn\n",
"\n",
"abcdef\r",
"hello\n",
"ab3\r",
"x2\r\r",
"1\r"
].join("");
var output = [
"hasrn\n",
"hasn\n",
"\n",
"hellof\n",
"ab3\r",
"x2\r",
"1\r"
].join("");
expect(escapeCarriageReturnSafe(input)).to.equal(output);
});
it("safely escapes single line: 1\r2\r3", function() {
var txt = escapeCarriageReturnSafe("1\r2\r3");
expect(txt).to.equal("3");
});
it("safely escapes single line: 1\r23\r4", function() {
var txt = escapeCarriageReturnSafe("1\r23\r4");
expect(txt).to.equal("23\r4");
});
it("safely escapes complicated single line", function() {
var txt = escapeCarriageReturnSafe("12\rabcdef\rg\rhi\rjklm\rn");
expect(txt).to.equal("abcdef\rjklm\rn");
});
});