webextension-store-meta
Version:
Get browser extension(webextension) item meta from Chrome Web Store, Firefox add-ons, and Microsoft Edge Add-ons.
47 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryJSONParseObject = exports.toStr = exports.toArray = exports.toPlainObject = exports.isPlainObject = exports.parseVersion = exports.parseNum = void 0;
const parseNum = (str) => {
const num = typeof str === "number"
? str
: str
? Number.parseFloat(String(str)
.replace(/^[^\d.]*/, "")
.replace(/^[\d,]+/g, (m) => m.replace(/,/g, "")))
: NaN;
return Number.isNaN(num) ? null : num;
};
exports.parseNum = parseNum;
const parseVersion = (str) => {
if (typeof str !== "string" || !str)
return null;
const match = /v?(\d+(?:\.\d+)+)/.exec(str);
return match ? match[1] : null;
};
exports.parseVersion = parseVersion;
const isPlainObject = (value) => !!value && value.constructor === Object;
exports.isPlainObject = isPlainObject;
const toPlainObject = (value) => {
if ((0, exports.isPlainObject)(value)) {
return value;
}
};
exports.toPlainObject = toPlainObject;
const toArray = (value) => {
if (Array.isArray(value)) {
return value;
}
};
exports.toArray = toArray;
const toStr = (value) => (typeof value === "string" && value.trim()) || null;
exports.toStr = toStr;
const tryJSONParseObject = (str) => {
try {
return (0, exports.toPlainObject)(JSON.parse(str));
}
catch (_e) {
return;
}
};
exports.tryJSONParseObject = tryJSONParseObject;
//# sourceMappingURL=parse.js.map