Remove require("os") from helpers to reduce dependencies for browser scenarios.

This commit is contained in:
David Anson 2021-12-27 03:41:43 +00:00 committed by GitHub
parent 9ec14f13a1
commit fd24b9552b
4 changed files with 20 additions and 20 deletions

View file

@ -25,12 +25,11 @@ module.exports = webpackEmptyContext;
/*!*****************************!*\
!*** ../helpers/helpers.js ***!
\*****************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
/***/ ((module) => {
"use strict";
// @ts-check
var os = __webpack_require__(/*! os */ "?591e");
// Regular expression for matching common newline characters
// See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js
var newLineRe = /\r\n?|\n/g;
@ -655,9 +654,10 @@ module.exports.emphasisMarkersInContent = emphasisMarkersInContent;
* Gets the most common line ending, falling back to the platform default.
*
* @param {string} input Markdown content to analyze.
* @param {string} [platform] Platform identifier (process.platform).
* @returns {string} Preferred line ending.
*/
function getPreferredLineEnding(input) {
function getPreferredLineEnding(input, platform) {
var cr = 0;
var lf = 0;
var crlf = 0;
@ -678,7 +678,8 @@ function getPreferredLineEnding(input) {
});
var preferredLineEnding = null;
if (!cr && !lf && !crlf) {
preferredLineEnding = os.EOL;
preferredLineEnding =
((platform || process.platform) === "win32") ? "\r\n" : "\n";
}
else if ((lf >= crlf) && (lf >= cr)) {
preferredLineEnding = "\n";
@ -4343,16 +4344,6 @@ module.exports = markdownit;
/***/ }),
/***/ "?591e":
/*!********************!*\
!*** os (ignored) ***!
\********************/
/***/ (() => {
/* (ignored) */
/***/ }),
/***/ "?ec0a":
/*!********************!*\
!*** fs (ignored) ***!

View file

@ -44,7 +44,6 @@ function config(options) {
"resolve": {
"fallback": {
"fs": false,
"os": false,
"path": false,
"util": false
}

View file

@ -2,8 +2,6 @@
"use strict";
const os = require("os");
// Regular expression for matching common newline characters
// See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js
const newLineRe = /\r\n?|\n/g;
@ -680,9 +678,10 @@ module.exports.emphasisMarkersInContent = emphasisMarkersInContent;
* Gets the most common line ending, falling back to the platform default.
*
* @param {string} input Markdown content to analyze.
* @param {string} [platform] Platform identifier (process.platform).
* @returns {string} Preferred line ending.
*/
function getPreferredLineEnding(input) {
function getPreferredLineEnding(input, platform) {
let cr = 0;
let lf = 0;
let crlf = 0;
@ -703,7 +702,8 @@ function getPreferredLineEnding(input) {
});
let preferredLineEnding = null;
if (!cr && !lf && !crlf) {
preferredLineEnding = os.EOL;
preferredLineEnding =
((platform || process.platform) === "win32") ? "\r\n" : "\n";
} else if ((lf >= crlf) && (lf >= cr)) {
preferredLineEnding = "\n";
} else if (crlf >= cr) {

View file

@ -387,7 +387,7 @@ test("forEachInlineCodeSpan", (t) => {
});
test("getPreferredLineEnding", (t) => {
t.plan(17);
t.plan(19);
const testCases = [
[ "", os.EOL ],
[ "\r", "\r" ],
@ -412,6 +412,16 @@ test("getPreferredLineEnding", (t) => {
const actual = helpers.getPreferredLineEnding(input);
t.is(actual, expected, "Incorrect line ending returned.");
});
t.is(
helpers.getPreferredLineEnding("", "linux"),
"\n",
"Incorrect line ending for linux"
);
t.is(
helpers.getPreferredLineEnding("", "win32"),
"\r\n",
"Incorrect line ending for win32"
);
});
test("applyFix", (t) => {