doff
Version:
A powerful tool to free your objects and arrays from unwanted content
25 lines (18 loc) • 498 B
JavaScript
;
// Load modules
const isPath = require('./isPath');
const LocalPath = require('./LocalPath');
const toString = require('./toString');
// Define exports
module.exports = function toLocalPath(fraction, base, target) {
if (LocalPath.isInstance(fraction)) {
return fraction;
}
const path = new LocalPath();
if (!isPath(fraction)) {
return path;
}
return path
.use(base)
.append(Array.isArray(target) ? `[${fraction}]` : toString(fraction), fraction);
};