Это так автор визауально разбивает один метод на несколько вариантов аргументов?
/
* @param name Cookie name
* @param value Cookie value
* @param expires Number of days until the cookies expires or an actual `Date`
* @param path Cookie path
* @param domain Cookie domain
* @param secure Secure flag
* @param sameSite OWASP samesite token `Lax`, `None`, or `Strict`. Defaults to `Lax`
*/
set(name: string, value: string, expires?: number | Date, path?: string, domain?: string, secure?: boolean, sameSite?: 'Lax' | 'None' | 'Strict'): void;
/@param name Cookie name
*
@param value Cookie value
*
@param expires Number of days until the cookies expires or an actual `Date`
*
@param path Cookie path
*
@param domain Cookie domain
*
@param secure Secure flag
*
@param sameSite OWASP samesite token `Lax`, `None`, or `Strict`. Defaults to `Lax`
*/
set(name: string, value: string, expires?: number | Date, path?: string, domain?: string, secure?: boolean, sameSite?: 'Lax' | 'None' | 'Strict'): void;
/
* Cookie's parameters:
* <pre>
* expires Number of days until the cookies expires or an actual
Date * path Cookie path
* domain Cookie domain
* secure Secure flag
* sameSite OWASP samesite token
Lax,
None, or
Strict. Defaults to
Lax * </pre>
*
@param name Cookie name
*
@param value Cookie value
*
@param options Body with cookie's params
*/
set(
name: string,
value: string,
options?: {
expires?: number | Date;
path?: string;
domain?: string;
secure?: boolean;
sameSite?: 'Lax' | 'None' | 'Strict';
}
): void;
set(
name: string,
value: string,
expiresOrOptions?: number | Date | any,
path?: string,
domain?: string,
secure?: boolean,
sameSite?: 'Lax' | 'None' | 'Strict'
): void {
if (!this.documentIsAccessible) {
return;
}
if (typeof expiresOrOptions === 'number' || expiresOrOptions instanceof Date || path || domain || secure || sameSite) {
const optionsBody = {
expires: expiresOrOptions,
path,
domain,
secure,
sameSite: sameSite ? sameSite : 'Lax',
};
this.set(name, value, optionsBody);
return;
}
let cookieString: string = encodeURIComponent(name) + '=' + encodeURIComponent(value) + ';';
const options = expiresOrOptions ? expiresOrOptions : {};
if (options.expires) {
if (typeof options.expires === 'number') {
const dateExpires: Date = new Date(new Date().getTime() + options.expires * 1000 * 60 * 60 * 24);
cookieString += 'expires=' + dateExpires.toUTCString() + ';';
} else {
cookieString += 'expires=' + options.expires.toUTCString() + ';';
}
}
if (options.path) {
cookieString += 'path=' + options.path + ';';
}
if (options.domain) {
cookieString += 'domain=' + options.domain + ';';
}
if (
options.secure === false && options.sameSite === 'None') {
options.secure = true;
console.warn(
[ngx-cookie-service] Cookie ${name} was forced with secure flag because sameSite=None. +
More details : https://github.com/stevermeister/ngx-cookie-service/issues/86#issuecomment-597720130 );
}
if (
options.secure) {
cookieString += 'secure;';
}
if (!options.sameSite) {
options.sameSite = 'Lax';
}
cookieString += 'sameSite=' + options.sameSite + ';';
this.document.cookie = cookieString;
}