Skip to content

Instantly share code, notes, and snippets.

View hunan-rostomyan's full-sized avatar

Hunan Rostomyan hunan-rostomyan

View GitHub Profile
@hunan-rostomyan
hunan-rostomyan / getCookie.ts
Created July 19, 2016 22:49
Get a cookie by name in TypeScript
// Given a cookie key `name`, returns the value of
// the cookie or `null`, if the key is not found.
function getCookie(name: string): string {
const nameLenPlus = (name.length + 1);
return document.cookie
.split(';')
.map(c => c.trim())
.filter(cookie => {
return cookie.substring(0, nameLenPlus) === `${name}=`;
})