Files
test-repo/tests_integration/path-serializer.js
T

28 lines
622 B
JavaScript
Raw Normal View History

2017-09-03 21:31:33 +08:00
"use strict";
2020-03-21 22:07:52 +02:00
const replaceCWD = (text) => {
const cwd = process.cwd();
const variants = /^[a-z]:\\/i.test(cwd)
? [
cwd.charAt(0).toLowerCase() + cwd.slice(1),
2020-03-21 22:07:52 +02:00
cwd.charAt(0).toUpperCase() + cwd.slice(1),
]
: [cwd];
for (const variant of variants) {
while (text.includes(variant)) {
text = text.replace(variant, "<cwd>");
}
}
return text;
};
2017-09-03 21:31:33 +08:00
module.exports = {
2020-03-21 22:07:52 +02:00
test: (value) =>
2017-09-28 19:30:51 +10:00
typeof value === "string" &&
2019-11-17 18:06:14 +08:00
(value.includes("\\") || value.includes(process.cwd())),
2017-09-03 21:31:33 +08:00
print: (value, serializer) =>
2020-03-21 22:07:52 +02:00
serializer(replaceCWD(value).replace(/\\/g, "/")),
2017-09-03 21:31:33 +08:00
};