1.0.0 • Published 7 years ago

@joshdoescode/browser-service v1.0.0

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
-
Last release
7 years ago

Browser Service

Angular 4 (CLI) Browser Service

Install

npm install @joshdoescode/browser-service

Add to your app.module

import { BrowserService } from '@joshdoescode/browser-service/src/browser.service';

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...
  ],
  providers: [
    ...
    BrowserService
  ],
  ...
})

Usage

Use inside your component, or another service.

All methods for this service are static, so there is no need to inject it.

Import the service

import {BrowserService} from "@joshdoescode/browser-service/src/browser.service";

Call the service

let id = BrowserService.getQuerystringValue('id');

Methods

Cookie names and querystring parameter names are case sensitive.

getQuerystringValue( name: string, url: string ): string

Returns null if the parameter name cannot be found in the querystring. Returns an empty string if the parameter is in the querystring, but has no value (e.g. '.../?bookcase'). Returns the value of the parameter, if one is set.

name - Name of the parameter to search for the value of.

url (optional) - The URL to analyse the querystring of. Default is the current URL.

setCookie( name: string, value: string, days: number )

Sets a cookie for the current domain called 'name', with a value of 'value', that will expire in 'days' days.

getCookie( name: string ): string

Returns the value of the cookie called 'name', or an empty string if one is not found.

removeCookie( name: string )

Removes a currently set cookie called 'name'.

1.0.0

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago