ngx-cookie-service
- Version 22.2.0
- Published
- 66.7 kB
- 1 dependency
- MIT license
Install
npm i ngx-cookie-serviceyarn add ngx-cookie-servicepnpm add ngx-cookie-serviceOverview
Angular cookie service
Index
Variables
Functions
Classes
Interfaces
Type Aliases
Variables
variable COOKIE_ENCODING
const COOKIE_ENCODING: InjectionToken<CookieEncoding>;The cookie value encoding for CookieService. Provide it with provideCookieEncoding.
@author: Pavankumar Jadda @since: 22.2.0
variable COOKIE_OPTIONS
const COOKIE_OPTIONS: InjectionToken<CookieOptions>;App-wide default options for CookieService. Provide them with provideCookieOptions.
@author: Pavankumar Jadda @since: 22.2.0
Functions
function provideCookieEncoding
provideCookieEncoding: (encoding: CookieEncoding) => EnvironmentProviders;Sets how CookieService encodes cookie values when writing them and decodes them when reading.
export const appConfig: ApplicationConfig = {providers: [provideCookieEncoding('minimal')],};Parameter encoding
'uri'(default),'minimal', or a custom CookieCodecReturns
Providers to add to the application config
@author: Pavankumar Jadda @since: 22.2.0
function provideCookieOptions
provideCookieOptions: (options: CookieOptions) => EnvironmentProviders;Sets default options for every
set(),delete()anddeleteAll()call of CookieService.Options passed to a call win over these defaults, and
undefinedvalues don't override them. A call that passes its ownexpiresreplaces the default one, sodelete()always expires the cookie.export const appConfig: ApplicationConfig = {providers: [provideCookieOptions({ path: '/', secure: true, sameSite: 'Strict' })],};Parameter options
Default cookie options
Returns
Providers to add to the application config
@author: Pavankumar Jadda @since: 22.2.0
Classes
class CookieService
class CookieService {}constructor
constructor();property ɵfac
static ɵfac: i0.ɵɵFactoryDeclaration<CookieService, never>;property ɵprov
static ɵprov: i0.ɵɵInjectableDeclaration<any>;method check
check: (name: string) => boolean;Return
trueif Document is accessible, otherwise returnfalseParameter name
Cookie name
Returns
boolean - whether cookie with specified name exists
@author: Stepan Suvorov @since: 1.0.0
method delete
delete: { ( name: string, path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite?: SameSite ): void; (name: string, options?: DeleteCookieOptions): void;};Delete cookie by name at given path and domain.
If
pathis not specified, noPathattribute is written and the browser uses its default path: the directory of the URL the page was loaded at (not the current router URL). To delete a cookie that was set withpath: '/', pass'/'here too.Parameter name
Cookie name
Parameter path
Cookie path
Parameter domain
Cookie domain
Parameter secure
Cookie secure flag
Parameter sameSite
Cookie sameSite flag - https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
@author: Stepan Suvorov @since: 1.0.0
Delete cookie by name. The options must match the attributes the cookie was set with:
pathanddomainselect the cookie, andpartitioned: trueis required to delete a Partitioned cookie.If
pathis not specified, noPathattribute is written and the browser uses its default path: the directory of the URL the page was loaded at (not the current router URL). To delete a cookie that was set withpath: '/', pass'/'here too.Parameter name
Cookie name
Parameter options
Cookie attributes:
path,domain,secure,sameSiteandpartitioned@author: Pavankumar Jadda @since: 22.1.0
method deleteAll
deleteAll: { ( path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite?: SameSite ): void; (options?: DeleteCookieOptions): void;};Delete all cookies at given path and domain.
If
pathis not specified, the browser's default path is used for each cookie, as described for delete.Parameter path
Cookie path
Parameter domain
Cookie domain
Parameter secure
Is the Cookie secure
Parameter sameSite
Is the cookie same site
@author: Stepan Suvorov @since: 1.0.0
Delete all cookies that can currently be accessed, using the same attributes for each one.
If
pathis not specified, the browser's default path is used for each cookie, as described for delete.Parameter options
Cookie attributes:
path,domain,secure,sameSiteandpartitioned@author: Pavankumar Jadda @since: 22.1.0
method get
get: (name: string) => string;Get cookies by name
Parameter name
Cookie name
Returns
property value
@author: Stepan Suvorov @since: 1.0.0
method getAll
getAll: () => Record<string, string>;Get all cookies in JSON format
Returns
all the cookies in json
@author: Stepan Suvorov @since: 1.0.0
method set
set: { ( name: string, value: string, expires?: CookieOptions['expires'], path?: CookieOptions['path'], domain?: CookieOptions['domain'], secure?: CookieOptions['secure'], sameSite?: SameSite, partitioned?: CookieOptions['partitioned'] ): void; (name: string, value: string, options?: CookieOptions): void;};Set cookie based on provided information
Parameter name
Cookie name
Parameter value
Cookie value
Parameter expires
Number of days until the cookies expires or an actual
DateParameter path
Cookie path
Parameter domain
Cookie domain
Parameter secure
Secure flag
Parameter partitioned
Partitioned flag
Parameter sameSite
OWASP same site token
Lax,None, orStrict. Defaults toLax@author: Stepan Suvorov @since: 1.0.0
Set cookie based on provided information
Cookie's parameters: expires Number of days until the cookies expires or an actual
Datepath Cookie path domain Cookie domain secure flag sameSite OWASP same site tokenLax,None, orStrict. Defaults toLaxParameter name
Cookie name
Parameter value
Cookie value
Parameter options
Body with cookie's params
@author: Stepan Suvorov @since: 1.0.0
Interfaces
interface CookieCodec
interface CookieCodec {}A custom encoding for cookie values, used with provideCookieEncoding.
encoderuns on every value written byset(), anddecodeon every value read byget()andgetAll(). Cookie names keep the default encoding. Ifdecodethrows, the raw value is returned instead.@author: Pavankumar Jadda @since: 22.2.0
interface CookieOptions
interface CookieOptions {}Type Aliases
type CookieEncoding
type CookieEncoding = 'uri' | 'minimal' | CookieCodec;How CookieService encodes cookie values:
-
'uri'(default):encodeURIComponentanddecodeURIComponent. -'minimal': values made only of characters allowed in a cookie value (RFC 6265 cookie-octets, except%) are written as-is, and other values are encoded withencodeURIComponent. This is the default of the jshttpcookiepackage used by Express, and keeps values such as JWTs and base64 readable by servers that don't URL-decode cookies. - A CookieCodec for a custom scheme.@author: Pavankumar Jadda @since: 22.2.0
type DeleteCookieOptions
type DeleteCookieOptions = Omit<CookieOptions, 'expires'>;Attributes that identify the cookie to delete. They must match the attributes the cookie was set with.
type SameSite
type SameSite = 'Lax' | 'None' | 'Strict';Package Files (1)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (2)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/ngx-cookie-service.
- Markdown[](https://www.jsdocs.io/package/ngx-cookie-service)
- HTML<a href="https://www.jsdocs.io/package/ngx-cookie-service"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 1640 ms. - Missing or incorrect documentation? Open an issue for this package.
