npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-cookie-monsters

v1.3.2

Published

>

Downloads

7

Readme

ngx-cookie-monster

Table of contents:

Getting Started

Installation

You can install this package locally with npm. To get the latest stable version and update package.json file:

npm install ngx-cookie-monsters --save

Usage

CookieModule should be registered in the AppModule with forRoot() static method and with forChild() in the child modules.
These methods accepts CookieOptions objects as well. Leave it blank for the defaults.

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { CookieModule } from 'ngx-cookie-monster';

import { AppComponent }  from './app.component';

@NgModule({
  imports: [ BrowserModule, CookieModule.forRoot() ],
  declarations: [ AppComponent ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }
import { Component } from '@angular/core';
import { NgxCookieMonsterService } from 'ngx-cookie-monster';

@Component({
    selector: 'nom-nom-nom',
    template: '<h1>come to the dark side, we have cookies</h1>'
})

export class AppComponent { 
  constructor(private cookieService: NgxCookieMonsterService){}
  
  getCookie(key: string) {
    return this.cookieService.get(key);
  }
}

CookieService

get()

Returns the value of given cookie key.

/**
 * @param key ID for lookup.
 * @returns Raw cookie value as string.
 */
get(key: string): string;

getObject()

Returns a deserialized Object of given cookie.

/**
 * @param key Id to use for lookup.
 * @returns deserialized cookied value.
 */
getObject(key: string): Object;

getAll()

Returns a key value object with all cookies

/**
 * @returns All cookies
 */
getAll(): any;

exists()

Evaluates if cookie exists

/**
 * @param key ID for lookup
 * @returns cookie existance
 */
exists(key: string): boolean;

create()

Create a cookie for the given key

/**
 * @param key ID
 * @param value stored raw.
 * @param (Optional) Options object.
 */
create(key: string, value: string, options?: CookieOptions): void;

createObject()

Create a cookie with an object of values

/**
 * @param key ID
 * @param value stored serialized
 * @param (Optional) Options object.
 */
createFromObject(key: string, value: Object, options?: CookieOptions): void;

remove()

Removes specific cookie

/**
 * @param key ID for lookup
 */
remove(key: string): void;

removeAll()

Removes all cookies.

/**
 */
removeAll(): void;

Options

Options object should be a type of CookieOptions interface. The object may have following properties:

  • domain - {string} - The cookie will be available only for this domain and its sub-domains. For security reasons the user agent will not accept the cookie
  • path - {string} - The cookie will be available only for this path and its sub-paths. By default, this is the URL that appears in your <base> tag. if the current domain is not a sub-domain of this domain or equal to it.
  • expires - {string | number | Date} - String of the form "Wdy, DD Mon YYYY HH:MM:SS GMT", number of the form milliseconds or minutes or hours or a Date object indicating the exact date/time this cookie will expire.
  • secure - {boolean} - If true, then the cookie will only be available through a secured connection.
  • httpOnly - {boolean} - If true, then the cookie will be set with the HttpOnly flag, and will only be accessible from the remote server. Helps to prevent against XSS attacks.
  • storeUnencoded - {boolean} - If true, then the cookie value will not be encoded and will be stored as provided.
  • sameSite - {'none' | 'lax' | 'strict'} - If strict, then it will prevent the cookie from being sent by the brwoser to the target site in all cross-site browsing context. If lax, then it will provide a reasonable balance between security and usabillity for websites that want to maintain user's logged-in session after the user arrives from an external link.