@freik/node-utils
Version:
My personal set of utilities for NodeJS
3 lines (2 loc) • 2.38 kB
JavaScript
var x=Object.create;var u=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var $=(t,r)=>{for(var n in r)u(t,n,{get:r[n],enumerable:!0})},f=(t,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of b(r))!j.call(t,e)&&e!==n&&u(t,e,{get:()=>r[e],enumerable:!(s=h(r,e))||s.enumerable});return t};var c=(t,r,n)=>(n=t!=null?x(W(t)):{},f(r||!t||!t.__esModule?u(n,"default",{value:t,enumerable:!0}):n,t)),v=t=>f(u({},"__esModule",{value:!0}),t);var T={};$(T,{basename:()=>R,changeExt:()=>k,dirname:()=>D,extname:()=>S,fileClean:()=>P,getExtNoDot:()=>d,getRoots:()=>I,getTemp:()=>V,join:()=>C,resolve:()=>z,trailingSlash:()=>w,xplat:()=>g});module.exports=v(T);var a=c(require("os")),A=c(require("child_process")),l=c(require("path")),p=require("fs"),m=require("util");const y=(0,m.promisify)(A.exec);function V(t,r){const n=r&&r[0]!=="."?"."+r:r||"";return l.join(a.tmpdir(),`${t}-tmp-${process.pid}${n}`)}function d(t){const r=l.extname(t);return r&&r.substring(1)}function k(t,r){const n=d(t);r&&r.length>1&&r[0]==="."&&(r=r.substring(1));let s=t.substring(0,t.length-n.length);return s.endsWith(".")||(s+="."),s+r}function g(t){return t.replaceAll("\\","/")}function w(t){return t.endsWith("\\")||t.endsWith("/")?g(t):g(t+l.sep)}function z(t){return g(l.resolve(g(t)))}function C(...t){return g(l.join(...t))}function D(t){return g(l.dirname(t))}async function I(){switch(a.platform()){case"win32":{const{stdout:t,stderr:r}=await y("wmic logicaldisk get name");return r.length>0?[]:t.split(`\r\r
`).filter(n=>/[A-Za-z]:/.test(n)).map(n=>n.trim())}case"darwin":return(await p.promises.readdir("/Volumes")).map(r=>l.join("/Volumes",r));default:return["linux NYI"]}}const O=[["?","\u0241"],["*","\u2217"],[":","\u0589"],[";","\u037E"],["/","\u2571"],["\\","\u2572"],["|","\u2503"],["<","\u02C2"],[">","\u02C3"]];function P(t,r){let n=t;for(const[i,o]of O)n.indexOf(i)>=0&&(n=n.replaceAll(i,o));n.endsWith(".")&&!r&&(n=n.substring(0,n.length-1)+"\u2024");const s=n.split('"');n="";let e=!0;for(let i=0;i<s.length;i++){const o=s[i];o===""?i===0?n+="\u201C":i!==s.length-1&&(n+=e?"\u201C":"\u201D",e=!e):o.endsWith(" ")?(e=!1,n+=o+"\u201C"):/[0-9]$/.test(o)?n+=o+"\u201D":i===s.length-1?n+=o:(n+=o+(e?"\u201C":"\u201D"),e=!e)}return n.trim()}const R=l.basename,S=l.extname;