UNPKG

moduloze

Version:

Convert CommonJS (CJS) modules to UMD and ESM formats

5 lines 2.24 kB
/*! Moduloze: helpers.js v0.9.1 (c) 2022 Kyle Simpson MIT License: http://getify.mit-license.org */ !function UMD(e,t,n,i){"function"==typeof define&&define.amd?(n=Object.values(n),define(e,n,i)):"undefined"!=typeof module&&module.exports?(n=Object.keys(n).map((e=>require(e))),module.exports=i(...n)):(n=Object.values(n).map((e=>t[e])),t[e]=i(...n))}("Helpers","undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:new Function("return this")(),{path:"NodePath",fs:"NodeFS",os:"NodeOS","@babel/types":"BabelTypes"},(function DEF(e,t,n,i){"use strict";var r=e,a=t,o=n,s=i;let u={findParentStatement:function findParentStatement(e){return s.isProgram(e.node)?null:s.isStatement(e.node)?e:findParentStatement(e.parentPath)}};u.isFunction=isFunction,u.isAssignmentTarget=function isAssignmentTarget(e){return!(s.isProgram(e.node)||s.isStatement(e.node)||isFunction(e)||s.isAssignmentPattern(e.node))&&(s.isAssignmentExpression(e.parent)?e.parent.left==e.node:isAssignmentTarget(e.parentPath))},u.expandHomeDir=expandHomeDir,u.addRelativeCurrentDir=function addRelativeCurrentDir(e){return r.isAbsolute(e)||/^(?:(?:\.+[/\\]+)|(?:~(?:[/\\].*)$))/.test(e)?e:`./${e}`},u.rootRelativePath=rootRelativePath,u.qualifyDepPaths=function qualifyDepPaths(e,t){var n=new Set,i={};for(let[a,o]of Object.entries(e)){if(n.has(o))throw new Error(`Dependency-map name conflict: ${o}`);{n.add(o);let e=r.resolve(t,expandHomeDir(a)),s=rootRelativePath(t,e);i[s]=o}}return i},u.isPathBasedSpecifier=function isPathBasedSpecifier(e){return/^(\.{0,2}|([a-z]+:)|~)[\/\\]/i.test(e)&&/\.[a-z]+$/.test(e)},u.isDirectory=function isDirectory(e){return checkPath(e)&&a.lstatSync(e).isDirectory()},u.checkPath=checkPath,u.generateName=function generateName(){do{var e=`Mz_${Math.round(1e9*Math.random())}`}while(e in c);return c[e]=!0,e};var d=o.homedir(),c={};function isFunction(e){return s.isFunctionDeclaration(e.node)||s.isFunctionExpression(e.node)}function expandHomeDir(e){return"~"!=e[0]||1!=e.length&&"/"!=e[1]||(e=e.replace(/^~/,d)),e}function rootRelativePath(e,t){var n=r.resolve(e,t);return r.relative(e,n)}function checkPath(e){return a.existsSync(e)}return u}));