@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 1.19 kB
JavaScript
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
import e from"./../assert/is-string.js";import r from"./../regexp/extended-length-path.js";import t from"./../string/lowercase.js";import i from"./../string/replace.js";var n=e.isPrimitive,a=r,o=t,m=i,s=/^([A-Za-z]):[\\\/]+/,u=/^\/([A-Za-z])\//;function p(e,r){var t,i,p;if(!n(e))throw new TypeError("invalid argument. First argument must be a string primitive. Value: `"+e+"`.");if(!n(r))throw new TypeError("invalid argument. Second argument must be a string primitive. Value: `"+r+"`.");if("win32"!==r&&"mixed"!==r&&"posix"!==r)throw new Error("invalid argument. Second argument must be a recognized output path convention. Value: `"+r+"`.");if(p=e,"win32"===r)return(i=u.exec(p))&&(t=i[1]+":\\",p=m(p,u,t)),m(p,"/","\\");if(a.test(e))throw new Error("invalid argument. Cannot convert Windows extended-length paths to POSIX paths. Value: `"+e+"`.");return"mixed"===r?((i=u.exec(p))?(t=i[1]+":/",p=m(p,u,t)):(i=s.exec(p))&&(t=i[1]+":/",p=m(p,s,t)),m(p,"\\","/")):((i=s.exec(p))&&(t="/"+o(i[1])+"/",p=m(p,s,t)),m(p,"\\","/"))}var g=p;export default g;
//# sourceMappingURL=convert-path.js.map