@teamsparta/cross-platform-logger
Version:
```typescript import * as CPL from "@teamsparta/cross-platform-logger";
70 lines • 2.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchPlatform = exports.getUrlParams = exports.getJSONfromUserInfoCookie = exports.setCookie = exports.getCookie = exports.isClient = void 0;
var isClient = function () {
return typeof window !== 'undefined' && typeof document !== 'undefined';
};
exports.isClient = isClient;
var getCookie = function (name) {
var _a, _b;
var value = "; ".concat(document.cookie);
var parts = value.split("; ".concat(name, "="));
if (parts.length === 2) {
var cookie = (_b = (_a = parts === null || parts === void 0 ? void 0 : parts.pop()) === null || _a === void 0 ? void 0 : _a.split(";")) === null || _b === void 0 ? void 0 : _b.shift();
return cookie ? decodeURIComponent(cookie) : "";
}
};
exports.getCookie = getCookie;
var setCookie = function (name, value, days) {
if (days === void 0) { days = null; }
var SPARTA_DOMAIN = ".spartacodingclub.kr";
var expires = "";
var domain = document.location.origin.includes(SPARTA_DOMAIN)
? SPARTA_DOMAIN
: document.location.hostname;
var sameSite = document.location.origin.includes(SPARTA_DOMAIN)
? "; SameSite=None; Secure"
: "";
var date = new Date();
date.setTime(days ? date.getTime() + days * 24 * 60 * 60 * 1000 : date.getTime());
expires = "; domain=".concat(domain, "; expires=").concat(date.toUTCString()).concat(sameSite);
document.cookie = name + "=" + (value || "") + expires + "; path=/";
};
exports.setCookie = setCookie;
var getJSONfromUserInfoCookie = function () {
var _a;
var output = { _id: '', name: '', phone: '', email: '', is_kko: false };
(_a = (0, exports.getCookie)('userinfo')) === null || _a === void 0 ? void 0 : _a.split(/\s*&\s*/).forEach(function (pair) {
var name = decodeURIComponent(pair.split('=')[0]);
output[name] = decodeURIComponent(pair.split('=')[1]);
});
return output;
};
exports.getJSONfromUserInfoCookie = getJSONfromUserInfoCookie;
var getUrlParams = function (key) {
if (typeof window === 'undefined')
return null;
var urlParams = new URLSearchParams(window.location.search);
var urlData = urlParams.get(key);
return urlData ? encodeURIComponent(urlData) : null;
};
exports.getUrlParams = getUrlParams;
var matchPlatform = function (ua) {
return (/(ipad)/.exec(ua) ||
/(ipod)/.exec(ua) ||
/(windows phone)/.exec(ua) ||
/(iphone)/.exec(ua) ||
/(kindle)/.exec(ua) ||
/(silk)/.exec(ua) ||
/(android)/.exec(ua) ||
/(win)/.exec(ua) ||
/(mac)/.exec(ua) ||
/(linux)/.exec(ua) ||
/(cros)/.exec(ua) ||
/(playbook)/.exec(ua) ||
/(bb)/.exec(ua) ||
/(blackberry)/.exec(ua) ||
[]);
};
exports.matchPlatform = matchPlatform;
//# sourceMappingURL=utils.js.map