mirror of
https://github.com/google/blockly.git
synced 2026-01-27 10:40:09 +01:00
refactor(build): Simplify implementation of posixPath
This commit is contained in:
@@ -11,23 +11,16 @@
|
||||
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* Escape regular expression pattern
|
||||
* @param {string} pattern regular expression pattern
|
||||
* @return {string} escaped regular expression pattern
|
||||
*/
|
||||
function escapeRegex(pattern) {
|
||||
return pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces OS-specific path with POSIX style path.
|
||||
* Simplified implementation based on
|
||||
* https://stackoverflow.com/a/63251716/4969945
|
||||
*
|
||||
* @param {string} target target path
|
||||
* @return {string} posix path
|
||||
*/
|
||||
function posixPath(target) {
|
||||
const osSpecificSep = new RegExp(escapeRegex(path.sep), 'g');
|
||||
return target.replace(osSpecificSep, path.posix.sep);
|
||||
return target.split(path.sep).join(path.posix.sep);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user