UNPKG

miniapp-web-jsapi

Version:

JSAPI/View adapter for miniprogram running on the web

57 lines 1.5 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import entries from './entries'; var JsUtils = /*#__PURE__*/function () { function JsUtils() { _classCallCheck(this, JsUtils); } _createClass(JsUtils, null, [{ key: "isString", value: function isString(value) { return typeof value === 'string'; } }, { key: "isFunction", value: function isFunction(value) { return typeof value === 'function'; } }, { key: "isNotEmpty", value: function isNotEmpty(value) { return value && value.length > 0; } }, { key: "isEmpty", value: function isEmpty(value) { return !JsUtils.isNotEmpty(value); } }, { key: "parseObjectSafe", value: function parseObjectSafe(content, def) { try { return JSON.parse(content); } catch (e) { console.warn('parseObjectSafe error: ', e); } return def; } }, { key: "encodeMap", value: function encodeMap(map) { if (!map) { return undefined; } var list = []; entries(map).forEach(function (entry) { var key = entry[0]; var value = entry[1]; if (value != null) { list.push("".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value))); } }); return list.length > 0 ? list.join('&') : undefined; } }]); return JsUtils; }(); export { JsUtils as default };