@modern-js/libuild-utils
Version:
utils for libuild
43 lines (42 loc) • 1.49 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTsLoader = exports.isTsExt = exports.isJsLoader = exports.isJsExt = exports.isStyleExt = exports.resolvePathAndQuery = void 0;
const querystring_1 = __importDefault(require("querystring"));
const resolvePathAndQuery = (originalPath) => {
const [filePath, queryStr] = originalPath.split('?');
const query = querystring_1.default.parse(queryStr !== null && queryStr !== void 0 ? queryStr : '');
for (const key of Object.keys(query)) {
if (query[key] === '') {
query[key] = true;
}
}
return {
query,
rawQuery: queryStr,
originalFilePath: filePath,
};
};
exports.resolvePathAndQuery = resolvePathAndQuery;
function isStyleExt(path) {
return /\.(c|le|sa|sc)ss(\?.*)?$/.test(path);
}
exports.isStyleExt = isStyleExt;
function isJsExt(path) {
return /\.(m|c)?(j|t)sx?(\?.*)?$/.test(path);
}
exports.isJsExt = isJsExt;
function isJsLoader(loader) {
return loader === 'js' || loader === 'ts' || loader === 'tsx' || loader === 'jsx';
}
exports.isJsLoader = isJsLoader;
function isTsExt(path) {
return /\.(m|c)?tsx?(\?.*)?$/.test(path);
}
exports.isTsExt = isTsExt;
function isTsLoader(loader) {
return loader === 'ts' || loader === 'tsx';
}
exports.isTsLoader = isTsLoader;