Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
line-endings.js62 linesDownload Raw Back to patch
1"use strict";
2var __assign = (this && this.__assign) || function () {
3    __assign = Object.assign || function(t) {
4        for (var s, i = 1, n = arguments.length; i < n; i++) {
5            s = arguments[i];
6            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7                t[p] = s[p];
8        }
9        return t;
10    };
11    return __assign.apply(this, arguments);
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.unixToWin = unixToWin;
15exports.winToUnix = winToUnix;
16exports.isUnix = isUnix;
17exports.isWin = isWin;
18function unixToWin(patch) {
19    if (Array.isArray(patch)) {
20        // It would be cleaner if instead of the line below we could just write
21        //     return patch.map(unixToWin)
22        // but mysteriously TypeScript (v5.7.3 at the time of writing) does not like this and it will
23        // refuse to compile, thinking that unixToWin could then return StructuredPatch[][] and the
24        // result would be incompatible with the overload signatures.
25        // See bug report at https://github.com/microsoft/TypeScript/issues/61398.
26        return patch.map(function (p) { return unixToWin(p); });
27    }
28    return __assign(__assign({}, patch), { hunks: patch.hunks.map(function (hunk) { return (__assign(__assign({}, hunk), { lines: hunk.lines.map(function (line, i) {
29                var _a;
30                return (line.startsWith('\\') || line.endsWith('\r') || ((_a = hunk.lines[i + 1]) === null || _a === void 0 ? void 0 : _a.startsWith('\\')))
31                    ? line
32                    : line + '\r';
33            }) })); }) });
34}
35function winToUnix(patch) {
36    if (Array.isArray(patch)) {
37        // (See comment above equivalent line in unixToWin)
38        return patch.map(function (p) { return winToUnix(p); });
39    }
40    return __assign(__assign({}, patch), { hunks: patch.hunks.map(function (hunk) { return (__assign(__assign({}, hunk), { lines: hunk.lines.map(function (line) { return line.endsWith('\r') ? line.substring(0, line.length - 1) : line; }) })); }) });
41}
42/**
43 * Returns true if the patch consistently uses Unix line endings (or only involves one line and has
44 * no line endings).
45 */
46function isUnix(patch) {
47    if (!Array.isArray(patch)) {
48        patch = [patch];
49    }
50    return !patch.some(function (index) { return index.hunks.some(function (hunk) { return hunk.lines.some(function (line) { return !line.startsWith('\\') && line.endsWith('\r'); }); }); });
51}
52/**
53 * Returns true if the patch uses Windows line endings and only Windows line endings.
54 */
55function isWin(patch) {
56    if (!Array.isArray(patch)) {
57        patch = [patch];
58    }
59    return patch.some(function (index) { return index.hunks.some(function (hunk) { return hunk.lines.some(function (line) { return line.endsWith('\r'); }); }); })
60        && patch.every(function (index) { return index.hunks.every(function (hunk) { return hunk.lines.every(function (line, i) { var _a; return line.startsWith('\\') || line.endsWith('\r') || ((_a = hunk.lines[i + 1]) === null || _a === void 0 ? void 0 : _a.startsWith('\\')); }); }); });
61}
62 
codekingpro/portable-devtools · Team Ai