0.1.0 • Published 7 years ago

webalize v0.1.0

Weekly downloads
94
License
MIT
Repository
github
Last release
7 years ago

Webalize text/url utils

Collection of text and url processing functions


API

Functions

looksLikeFile(urlParam) ⇒ boolean

Filters file urls from template urls

Kind: global function

ParamType
urlParamany

Example

url.looksLikeFile('/assets/img/some_image.png?v=132') // === true

webalize(str) ⇒ string

Kind: global function

ParamType
strstring

Example

url.webalize('-Ňějaký čupr', true) // === 'nejaky-cupr'

camelcaseToWebalized(str) ⇒ string

Makes url nice.

Kind: global function

ParamTypeDescription
strstringShould not start with lowercase character

Example

url.camelcaseToWebalized('helloWorld') // === 'hello-world'

toCamelCase(str, withDiacritics) ⇒ string

Makes camelcase from nice url (reverse to camelcaseToWebalized)

Kind: global function

ParamTypeDefault
strstring
withDiacriticsbooleanfalse

Example

url.toCamelCase('ŇěJaký čupr', true) // === 'nejakyCupr'

webalizeChunks(string, separator) ⇒ string

Makes nice url from template path

Kind: global function

ParamTypeDefault
stringstring
separatorstring"'/'"

Example

url.webalizeChunks('/blahBlah/haHa'), '/blah-blah/ha-ha'

camelCaseChunks(string, separator) ⇒ string

Parses url path to template path

Kind: global function

ParamTypeDefault
stringstring
separatorstring"'/'"

Example

url.camelCaseChunks('/blah-blah/ha-ha') // === '/blahBlah/haHa'

asTemplateUrl(path, urlParam, homeView, notFoundView) ⇒ string | null

Makes template path when possible, otherwise returns notFoundView

Kind: global function

ParamTypeDefaultDescription
pathstringpath part of url
urlParamstringwhole url
homeViewanyhome view template for / path
notFoundViewany

withParams(urlParam) ⇒ string

Adds parameter to querystring or hash

Kind: global function

ParamTypeDescription
urlParamstring
options.queryObject | nullquerystring object (null removes query)
options.hashObject | nullhash object (null removes hash)

Example

const res = url.withParams('http://www.google.com?foo=1&bar=&x=hello', { query: { x: 1, y: 2 } });
assert.equal(res, 'http://www.google.com/?foo=1&bar=&x=1&y=2');

replaceDiacritics(str) ⇒ string

Replaces all diacritics

Kind: global function

ParamType
strstring