source: trip-planner-front/node_modules/uri-js/dist/esnext/schemes/urn.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1import { SCHEMES } from "../uri";
2const NID$ = "(?:[0-9A-Za-z][0-9A-Za-z\\-]{1,31})";
3const PCT_ENCODED$ = "(?:\\%[0-9A-Fa-f]{2})";
4const TRANS$$ = "[0-9A-Za-z\\(\\)\\+\\,\\-\\.\\:\\=\\@\\;\\$\\_\\!\\*\\'\\/\\?\\#]";
5const NSS$ = "(?:(?:" + PCT_ENCODED$ + "|" + TRANS$$ + ")+)";
6const URN_SCHEME = new RegExp("^urn\\:(" + NID$ + ")$");
7const URN_PATH = new RegExp("^(" + NID$ + ")\\:(" + NSS$ + ")$");
8const URN_PARSE = /^([^\:]+)\:(.*)/;
9const URN_EXCLUDED = /[\x00-\x20\\\"\&\<\>\[\]\^\`\{\|\}\~\x7F-\xFF]/g;
10//RFC 2141
11const handler = {
12 scheme: "urn",
13 parse: function (components, options) {
14 const matches = components.path && components.path.match(URN_PARSE);
15 let urnComponents = components;
16 if (matches) {
17 const scheme = options.scheme || urnComponents.scheme || "urn";
18 const nid = matches[1].toLowerCase();
19 const nss = matches[2];
20 const urnScheme = `${scheme}:${options.nid || nid}`;
21 const schemeHandler = SCHEMES[urnScheme];
22 urnComponents.nid = nid;
23 urnComponents.nss = nss;
24 urnComponents.path = undefined;
25 if (schemeHandler) {
26 urnComponents = schemeHandler.parse(urnComponents, options);
27 }
28 }
29 else {
30 urnComponents.error = urnComponents.error || "URN can not be parsed.";
31 }
32 return urnComponents;
33 },
34 serialize: function (urnComponents, options) {
35 const scheme = options.scheme || urnComponents.scheme || "urn";
36 const nid = urnComponents.nid;
37 const urnScheme = `${scheme}:${options.nid || nid}`;
38 const schemeHandler = SCHEMES[urnScheme];
39 if (schemeHandler) {
40 urnComponents = schemeHandler.serialize(urnComponents, options);
41 }
42 const uriComponents = urnComponents;
43 const nss = urnComponents.nss;
44 uriComponents.path = `${nid || options.nid}:${nss}`;
45 return uriComponents;
46 },
47};
48export default handler;
49//# sourceMappingURL=urn.js.map
Note: See TracBrowser for help on using the repository browser.