Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pragonauts/webalize
Utilities for replacing diacritics and camelcase notations
https://github.com/pragonauts/webalize
nodejs pragonauts text-util
Last synced: about 1 month ago
JSON representation
Utilities for replacing diacritics and camelcase notations
- Host: GitHub
- URL: https://github.com/pragonauts/webalize
- Owner: pragonauts
- Created: 2016-12-14T14:08:51.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-02T12:09:09.000Z (almost 8 years ago)
- Last Synced: 2024-09-29T18:01:37.475Z (about 2 months ago)
- Topics: nodejs, pragonauts, text-util
- Language: JavaScript
- Size: 9.77 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Webalize text/url utils
Collection of text and url processing functions
-----------------
# API
## Functions
-
looksLikeFile(urlParam) ⇒boolean
-
Filters file urls from template urls
-
webalize(str) ⇒string
-
camelcaseToWebalized(str) ⇒string
-
Makes url nice.
-
toCamelCase(str, [withDiacritics]) ⇒string
-
Makes camelcase from nice url (reverse to camelcaseToWebalized)
-
webalizeChunks(string, [separator]) ⇒string
-
Makes nice url from template path
-
camelCaseChunks(string, [separator]) ⇒string
-
Parses url path to template path
-
asTemplateUrl(path, urlParam, homeView, [notFoundView]) ⇒string
|null
-
Makes template path when possible, otherwise returns notFoundView
-
withParams(urlParam) ⇒string
-
Adds parameter to querystring or hash
-
replaceDiacritics(str) ⇒string
-
Replaces all diacritics
## looksLikeFile(urlParam) ⇒ boolean
Filters file urls from template urls
**Kind**: global function
| Param | Type |
| --- | --- |
| urlParam | any
|
**Example**
```javascript
url.looksLikeFile('/assets/img/some_image.png?v=132') // === true
```
## webalize(str) ⇒ string
**Kind**: global function
| Param | Type |
| --- | --- |
| str | string
|
**Example**
```javascript
url.webalize('-Ňějaký čupr', true) // === 'nejaky-cupr'
```
## camelcaseToWebalized(str) ⇒ string
Makes url nice.
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| str | string
| Should not start with lowercase character |
**Example**
```javascript
url.camelcaseToWebalized('helloWorld') // === 'hello-world'
```
## toCamelCase(str, [withDiacritics]) ⇒ string
Makes camelcase from nice url (reverse to camelcaseToWebalized)
**Kind**: global function
| Param | Type | Default |
| --- | --- | --- |
| str | string
| |
| [withDiacritics] | boolean
| false
|
**Example**
```javascript
url.toCamelCase('ŇěJaký čupr', true) // === 'nejakyCupr'
```
## webalizeChunks(string, [separator]) ⇒ string
Makes nice url from template path
**Kind**: global function
| Param | Type | Default |
| --- | --- | --- |
| string | string
| |
| [separator] | string
| "'/'"
|
**Example**
```javascript
url.webalizeChunks('/blahBlah/haHa'), '/blah-blah/ha-ha'
```
## camelCaseChunks(string, [separator]) ⇒ string
Parses url path to template path
**Kind**: global function
| Param | Type | Default |
| --- | --- | --- |
| string | string
| |
| [separator] | string
| "'/'"
|
**Example**
```javascript
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
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| path | string
| | path part of url |
| urlParam | string
| | whole url |
| homeView | any
| | home view template for / path |
| [notFoundView] | any
| | |
## withParams(urlParam) ⇒ string
Adds parameter to querystring or hash
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| urlParam | string
| |
| options.query | Object
| null
| querystring object (null removes query) |
| options.hash | Object
| null
| hash object (null removes hash) |
**Example**
```javascript
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
| Param | Type |
| --- | --- |
| str | string
|