Framework

- About
- Guides
- Community
- API
- Code
- Download

# Kanso API Documentation

Index | View on single page

## core

The core module contains functions used by kanso to facilitate the running of your app. You shouldn't need to use any of the functions here directly unless you're messing with the internals of Kanso.

### rewriteGroups(pattern, url)

Extracts groups from a url, eg: '/some/path' with pattern '/some/:name' -> {name: 'path'}

#### Parameters

pattern | String |
url | String |

Returns: Object

### rewriteSplat(pattern, url)

Extracts a splat value from a rewrite pattern and matching URL.

#### Parameters

pattern | String |
url | String |

Returns: String

### matchURL(method, url)

Attempts to match rewrite from patterns to a URL, returning the matching rewrite object if successful.

#### Parameters

method | String |
url | String |

Returns: Object

### replaceGroups(val, groups, splat)

Replace group names in a string with the value of that group eg: "/:name" with groups {name: 'test'} -> "/test"

#### Parameters

val | String |
groups | Object |
splat | String |

Returns: String

### createRequest(method, url, data, match, callback)

Creates a new request object from a url and matching rewrite object. Query parameters are automatically populated from rewrite pattern.

#### Parameters

method | String |
url | String |
data | Object |
match | Object |
callback | Function |

### runShowBrowser(req, name, docid, callback)

Fetches the relevant document and calls the named show function.

#### Parameters

req | Object |
name | String |
docid | String |
callback | Function |

### parseResponse(req, res)

Helper for runShow/runList.

#### Parameters

req | Object |
res | Object |

### runShow(fn, doc, req)

Runs a show function with the given document and request object, emitting relevant events. This function runs both server and client-side.

#### Parameters

fn | Function |
doc | Object |
req | Object |

### runUpdateBrowser(req, name, docid, callback)

Fetches the relevant document and calls the named update function.

#### Parameters

req | Object |
name | String |
docid | String |
callback | Function |

### runUpdate(fn, doc, req)

Runs a update function with the given document and request object, emitting relevant events. This function runs both server and client-side.

#### Parameters

fn | Function |
doc | Object |
req | Object |

### createHead(data)

Creates a fake head object from view results for passing to a list function being run client-side.

#### Parameters

data | Object |

Returns: Object

### runListBrowser(req, name, view, callback)

Fetches the relevant view and calls the named list function with the results.

#### Parameters

req | Object |
name | String |
view | String |
callback | Function |

### runList(fn, head, req)

Runs a list function with the given document and request object, emitting relevant events. This function runs both server and client-side.

#### Parameters

fn | Function |
head | Object |
req | Object |

### handle(method, url, data)

Creates a request object for the url and runs appropriate show, list or update functions.

#### Parameters

method | String |
url | String |
data | Object |

### setURL(method, url, data)

Add a history entry for the given url, prefixed with the baseURL for the app.

#### Parameters

method | String |
url | String |
data | Object | (optional)

### getURL()

Gets the current app-level URL (without baseURL prefix).

Returns: String

### sameOrigin(a, b)

Tests is two urls are of the same origin. Accepts parsed url objects or strings as arguments.

#### Parameters

a |  |
b |  |

Returns: Boolean

### appPath(p)

Converts a full url to an app-level url (without baseURL prefix). example: {baseURL}/some/path -> /some/path

#### Parameters

p | String |

Returns: String

### isAppURL(url)

Used to decide whether to handle a link or not. Should detect app vs. external urls.

#### Parameters

url | String |

Returns: Boolean