Updates
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Parse request cookies
|
||||
* ============================================================================== *
|
||||
* @description This function takes in a request object and returns the cookies as a JS object
|
||||
*/
|
||||
export default function (): {
|
||||
[s: string]: any;
|
||||
} | null;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = default_1;
|
||||
/**
|
||||
* Parse request cookies
|
||||
* ============================================================================== *
|
||||
* @description This function takes in a request object and returns the cookies as a JS object
|
||||
*/
|
||||
function default_1() {
|
||||
/**
|
||||
* Check inputs
|
||||
*
|
||||
* @description Check inputs
|
||||
*/
|
||||
const cookieString = document.cookie;
|
||||
if (!cookieString || typeof cookieString !== "string") {
|
||||
return null;
|
||||
}
|
||||
const cookieSplitArray = cookieString.split(";");
|
||||
let cookieObject = {};
|
||||
cookieSplitArray.forEach((keyValueString) => {
|
||||
const [key, value] = keyValueString.split("=");
|
||||
if (key && typeof key == "string") {
|
||||
cookieObject[key.replace(/^ +| +$/, "")] =
|
||||
value && typeof value == "string"
|
||||
? value.replace(/^ +| +$/, "")
|
||||
: null;
|
||||
}
|
||||
});
|
||||
return cookieObject;
|
||||
}
|
||||
Reference in New Issue
Block a user