Repository URL to install this package:
|
Version:
4.0.5 ▾
|
import { config } from '../config'
import { Serializable, CookieGenerateOptions } from '../typings'
import { toOptionsWithDefaults } from './toOptionsWithDefaults'
import { generateCookieString } from './generateCookieString'
import { getExpiresDate } from './getExpiresDate'
import { updateCachedDocumentCookie } from './renewCache'
// import { get } from './get'
// import { has } from './has'
export const set = (
key: string,
// value: string | number | boolean,
value?: Serializable,
optionsArg?: CookieGenerateOptions
) => {
const options = toOptionsWithDefaults(optionsArg)
options.expires = getExpiresDate(
value === undefined ? new Date(-1000000000000000) : options.expires || -1
)
config.get('cache')[key] = value as string
config.get('document').cookie = generateCookieString(key, value, options)
// updateCachedDocumentCookie()
// chain with the get set has and others...
// return { get, set, has }
}