2.0.0 • Published 2 years ago

mdurl v2.0.0

Weekly downloads
3,192,774
License
MIT
Repository
github
Last release
2 years ago

mdurl

CI NPM version

URL utilities for 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, 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.

License

MIT

markdown-it@ctxhou/markdown-it@sup39/markdown-it@infinitebrahmanuniverse/nolb-mdu@saaspe/components@everything-registry/sub-chunk-2148storybook-addon-markdown-docssvelte-component-libvremark-parsevite-plugin-md-plusvelpp@docus/core@docus/mdc@docus/mdc-edge@cosmicmedia/markdown-it@blkmarketco/components-library@rstacruz/pnpm@rdx-js/rdxjs-slate-markdown-serializerzzzxxxyyy321123stemcstudio-markdowntyped-mdast-util-to-hasttingzi-vuepresstheme-patternfly-orgtldrawlignin@argdown/core@adobe/hypermedia-pipeline@bitsler/markdown-it@bloodf/nuxt-content@breakaway/theme-patternfly-org@breakaway/documentation-framework@buganto/client@byloth/vue-content@cdk8s-extensions/argo-rollout@aboveyou00/markdown-it@cnblogs/markdown-it@darren-valent/cdk-ec2-key-pairzhihu-markdownzona-xvue3-google-login-with-stateuni-navurl-unshortzjx-markdown-it@hanye9895/markdown-it@hackmd/markdown-it@farnabaz/content@farnabaz/nuxt-mdc@gerhobbelt/markdown-it@globalbrain/markdown-it@lego-js/tests@mattermost/commonmark@mrkindy/prosemirror-tables@markflowy/editor@fanfix/nestjs-firebase@mdoc/mdast-util-to-hast@minmaxindustries/mws-sdk@minodisk/medmd@molgenis-ui/core-ui@molgenis/core-ui@molgenis/rsql@molgenis/rsql-js@om-tlh/markdown-it@realzh/rz-markdown-it@starzkg/vuepress-plugin-markdown-enhance@open-wc/demoing-storybook@podlubnaja/ui-kit@patternfly/documentation-framework@object-studio/react-native-web@nuxt/content-edge@parkcedar/leaflet@skeetboothppq/component-library@shivarajapple/first-library@sharshar/date-libminimauscgamecocksandstormminttown_pf_communitymicrojammyui5librarymobomyreuselibrarymyui5librarychenowt-client-javascriptparvan_componentsparvan_reactjs_componentspanzx-storereact-native-linkifyreact-native-hyperlinkrsql-jssandai-corereact-native-nayanreact-form-component-librarysequelcomponentpf-docsshowgallerygrape-weblystable-commonmarkmarkdown-it-hyperzmarkdown-it-faxesmarkdown-it-for-mdvcmarkdown-themmarkdown-to-bbcodemarkdown-it-weflex
2.0.0

2 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.1

10 years ago