Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/cookies / src / core / set.ts
Size: Mime:
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 }
}