0.2.2 • Published 2 years ago

erre-ele v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Erre Ele

A Typescript browser URL manager

Activity

License GitHub issues GitHub all releases GitHub Workflow Status npm

Why?

Why not.

Install

npm i erre-ele --save

Usage

Import

Import the ErreEle singleton instance:

import rl from 'erre-ele';

Interface

Review and use to your implementations how the IErreEle interface looks

export interface IErreEle<S> {
  getParamFromURL: (pn: string) => string | null;
  getPathnameFromURL: () => string | null;
  go: (p: string, t?: string, s?: S) => void;
  subscribeOnPopState: (onPopState?: (e: PopStateEvent) => void) => void;
  setParam: (key: string, value: string) => void;
  getParam: (key: string) => void;
}

Generic

<S> State type to push in browser history.

Public API

Public APIDescription
getParamFromURLGet param value from URL
getPathnameFromURLGet path name from URL
goPush in browser history
subscribeOnPopStateSubscribe handler when pop state in history
paramsURL params state
setParamSet new param state
getParamGet new param state

Usage

// Browser URL "https://example.com/?foo=bar"

import rl from 'erre-ele';

const fooValue = rl.getParamFromURL('foo');  // bar