Skip to content

javierlopezdeancos/erre-ele

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 API Description
getParamFromURL Get param value from URL
getPathnameFromURL Get path name from URL
go Push in browser history
subscribeOnPopState Subscribe handler when pop state in history
params URL params state
setParam Set new param state
getParam Get new param state

Usage

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

import rl from 'erre-ele';

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