UNPKG

wangyj

Version:

wangyj 个人常用命令库

25 lines (24 loc) 856 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getHostOrigin = exports.setOrigin = exports.getOrigin = void 0; const node_child_process_1 = require("node:child_process"); const getOrigin = () => { return (0, node_child_process_1.execSync)("npm get registry", { encoding: "utf-8" }); }; exports.getOrigin = getOrigin; const setOrigin = (origin) => { try { (0, node_child_process_1.execSync)(`npm config set registry ${origin}`, { encoding: "utf-8" }); return { res: true }; } catch (error) { return { res: true, error }; } }; exports.setOrigin = setOrigin; const getHostOrigin = (url) => { const arr = url.split(""); const host = arr[arr.length - 1] == "/" ? arr.pop() && arr.join("") : arr.join("").trim(); return host; }; exports.getHostOrigin = getHostOrigin;