Skip to content
Ankit Patel edited this page Aug 12, 2017 · 9 revisions

Primary Operations

check(...identifiers)(...checks)

identifier: string, check: regex literal/object

Create a validation object to check one or more identifiers with one or more regular expressions (literal/object form). The returned object has keys that are identifiers and values are corresponding regex checks wrapped in an executable function.

let yearChk = check(':year')(/^201[0-7]$/) // 2010 - 2017
let typeColorChk = check(':type', ':color')(/.{3}/, /^[a-z]+$/) // at least 3 characters

spec(...pathKeys)(next, err?, fail?)

pathKey: string, next,err,fail: function

Create a spec over one or more path keys and actions.

// show vehicle "type" by "year" or "color"
let vehicleSpec = spec('/:type', '/:type/:year', '/:type/:color')(next, err, fail)

match(specs, checks?, matchCheck?)

specs: object or [object], checks: object, matchCheck: function

Create a match object from one or more specs. Pass checks object to validate identifiers. Pass matchCheck function to modify current route path before specs are executed.

let vehicleMatcher = match(vehicleSpec, {...yearChk, ...typeColorChk})

container(matchers, mismatchers?, instance?, scheduleDispatch?)

matchers, mismatchers: object or [object], instance: object, scheduleDispatch: boolean

Creates an ultra instance that runs provided matchers for the current url and registers a listener to handle pushstate routing. Pass ultra instance to update that instance with new matchers. scheduleDispatch controls if current url should be dispatched. scheduleDispatch is true by default if an instance is not provided or if the provided instance has not dispatched yet. Override the default value by providing true/false.

let ultra = container(vehicleMatcher)
/*** example run ***/
/*

next: called on exact match for sample routes
  /automobile or /motorcycle
  /automobile/red or /automobile/2017
  /motorcycle/blue or /motorcycle/2017

err: called on partial match
  /automobile/2020 or /motorcycle/z

fail: called after matching is complete and spec did not match
  /z

*/

Other Operations

prefixMatch

miss

toggle

toggleSelected

a.link

Utility Functions

assignValues

parseQS

prependPath

appendPath

scheduleTask

Clone this wiki locally