Comparing version 0.0.1 to 1.0.0
@@ -11,7 +11,7 @@ | ||
// | ||
function getEncodeCache(unescapedSet) { | ||
var i, ch, cache = encodeCache[unescapedSet]; | ||
function getEncodeCache(exclude) { | ||
var i, ch, cache = encodeCache[exclude]; | ||
if (cache) { return cache; } | ||
cache = encodeCache[unescapedSet] = []; | ||
cache = encodeCache[exclude] = []; | ||
@@ -29,4 +29,4 @@ for (i = 0; i < 128; i++) { | ||
for (i = 0; i < unescapedSet.length; i++) { | ||
cache[unescapedSet.charCodeAt(i)] = unescapedSet[i]; | ||
for (i = 0; i < exclude.length; i++) { | ||
cache[exclude.charCodeAt(i)] = exclude[i]; | ||
} | ||
@@ -42,13 +42,13 @@ | ||
// - string - string to encode | ||
// - unescapedSet - list of characters to ignore (in addition to a-zA-Z0-9) | ||
// - exclude - list of characters to ignore (in addition to a-zA-Z0-9) | ||
// - keepEscaped - don't encode '%' in a correct escape sequence (default: true) | ||
// | ||
function encode(string, unescapedSet, keepEscaped) { | ||
function encode(string, exclude, keepEscaped) { | ||
var i, l, code, nextCode, cache, | ||
result = ''; | ||
if (typeof unescapedSet !== 'string') { | ||
if (typeof exclude !== 'string') { | ||
// encode(string, keepEscaped) | ||
keepEscaped = unescapedSet; | ||
unescapedSet = encode.defaultChars; | ||
keepEscaped = exclude; | ||
exclude = encode.defaultChars; | ||
} | ||
@@ -60,3 +60,3 @@ | ||
cache = getEncodeCache(unescapedSet); | ||
cache = getEncodeCache(exclude); | ||
@@ -63,0 +63,0 @@ for (i = 0, l = string.length; i < l; i++) { |
@@ -5,1 +5,4 @@ 'use strict'; | ||
module.exports.encode = require('./encode'); | ||
module.exports.decode = require('./decode'); | ||
module.exports.format = require('./format'); | ||
module.exports.parse = require('./parse'); |
{ | ||
"name": "mdurl", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "URL utilities for markdown-it", | ||
@@ -5,0 +5,0 @@ "repository": "markdown-it/mdurl", |
@@ -6,6 +6,98 @@ # mdurl | ||
URL utilities for [markdown-it](https://github.com/markdown-it/markdown-it) parser. | ||
> URL utilities for [markdown-it](https://github.com/markdown-it/markdown-it) parser. | ||
## API | ||
### .encode(str [, exclude, keepEncoded]) -> String | ||
Percent-encode a string, avoiding double encoding. Don't touch `/a-zA-Z0-9/` + | ||
excluded chars + `/%[a-fA-F0-9]{2}/` (if not disabled). Broken surrorates are | ||
replaced with `U+FFFD`. | ||
Params: | ||
- __str__ - input string. | ||
- __exclude__ - optional, `;/?:@&=+$,-_.!~*'()#`. Additional chars to keep intact | ||
(except `/a-zA-Z0-9/`). | ||
- __keepEncoded__ - optional, `true`. By default it skips already encoded sequences | ||
(`/%[a-fA-F0-9]{2}/`). If set to `false`, `%` will be encoded. | ||
### encode.defaultChars, encode.componentChars | ||
You can use these constants as second argument to `encode` function. | ||
- `encode.defaultChars` is the same exclude set as in the standard `encodeURI()` function | ||
- `encode.componentChars` is the same exclude set as in the `encodeURIComponent()` function | ||
For example, `encode('something', encode.componentChars, true)` is roughly the equivalent of | ||
the `encodeURIComponent()` function (except `encode()` doesn't throw). | ||
### .decode(str [, exclude]) -> String | ||
Decode percent-encoded string. Invalid percent-encoded sequences (e.g. `%2G`) | ||
are left as is. Invalid UTF-8 characters are replaced with `U+FFFD`. | ||
Params: | ||
- __str__ - input string. | ||
- __exclude__ - set of characters to leave encoded, optional, `;/?:@&=+$,#`. | ||
### decode.defaultChars, decode.componentChars | ||
You can use these constants as second argument to `decode` function. | ||
- `decode.defaultChars` is the same exclude set as in the standard `decodeURI()` function | ||
- `decode.componentChars` is the same exclude set as in the `decodeURIComponent()` function | ||
For example, `decode('something', decode.defaultChars)` has the same behavior as | ||
`decodeURI('something')` on a correctly encoded input. | ||
### .parse(url, slashesDenoteHost) -> urlObs | ||
Parse url string. Similar to node's [url.parse](http://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost), but without any | ||
normalizations and query string parse. | ||
- __url__ - input url (string) | ||
- __slashesDenoteHost__ - if url starts with `//`, expect a hostname after it. Optional, `false`. | ||
Result (hash): | ||
- protocol | ||
- slashes | ||
- auth | ||
- port | ||
- hostname | ||
- hash | ||
- search | ||
- pathname | ||
Difference with node's `url`: | ||
1. No leading slash in paths, e.g. in `url.parse('http://foo?bar')` pathname is | ||
``, not `/` | ||
2. Backslashes are not replaced with slashes, so `http:\\example.org\` is | ||
treated like a relative path | ||
3. Trailing colon is treated like a part of the path, i.e. in | ||
`http://example.org:foo` pathname is `:foo` | ||
4. Nothing is URL-encoded in the resulting object, (in joyent/node some chars | ||
in auth and paths are encoded) | ||
5. `url.parse()` does not have `parseQueryString` argument | ||
6. Removed extraneous result properties: `host`, `path`, `query`, etc., | ||
which can be constructed using other parts of the url. | ||
### .format(urlObject) | ||
Format an object previously obtained with `.parse()` function. Similar to node's | ||
[url.format](http://nodejs.org/api/url.html#url_url_format_urlobj). | ||
## License | ||
[MIT](https://github.com/markdown-it/mdurl/blob/master/LICENSE) |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
21968
9
462
0
103
1
80
1