UNPKG

sk-js

Version:
136 lines (119 loc) 3.3 kB
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } import Proxy0 from './Proxy0'; import SK from './SK'; var Window0 = /*#__PURE__*/ function () { function Window0() { _classCallCheck(this, Window0); } _createClass(Window0, null, [{ key: "getCurrentHref", /** * the url of page or sub frame page * * @returns {string} */ value: function getCurrentHref() { return window.location.href; } /** * window.location.origin * * @returns {string} */ }, { key: "getCurrentOrigin", value: function getCurrentOrigin() { return window.location.origin; } /** * /a/b -> /a/b * /a/b/c.html -> /a/b/c * /context/a -> /a * * @returns {string} */ }, { key: "getCurrentPath", value: function getCurrentPath() { var path = window.location.pathname; path = path.substring(SK.DEFAULT_CONTEXT_PATH.length, path.length); path = Proxy0._.endsWith(path, SK.FILE_TYPE_HTML_WITH_POINT) ? path.substring(0, path.length - 5) : path; return path; } /** * ?a=1&b=2 * * @returns {*} */ }, { key: "getCurrentSearch", value: function getCurrentSearch() { return window.location.search; } /** * (a,?a=1&b=2) -> 1 * * @param param * @param search * @returns {*} */ }, { key: "getRequestParameter", value: function getRequestParameter(param) { var search = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SK.getCurrentSearch(); return SK.getRequestParameter(param, search); } /** * localStorage * * @param key * @param value */ }, { key: "local", value: function local(key, value) { if (arguments.length > 1) { localStorage.removeItem(key); if (!Proxy0._.isNil(value)) { return localStorage.setItem(key, value); } } else { return localStorage.getItem(key); } } /** * web redirect * * @param url */ }, { key: "redirect", value: function redirect(url) { window.location.href = url; } /** * sessionStorage * * @param key * @param value */ }, { key: "session", value: function session(key, value) { if (arguments.length > 1) { sessionStorage.removeItem(key); if (!Proxy0._.isNil(value)) { return sessionStorage.setItem(key, value); } } else { return sessionStorage.getItem(key); } } }]); return Window0; }(); export { Window0 as default };