Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/uri-js/src/schemes/urn-uuid.ts')
-rw-r--r--node_modules/uri-js/src/schemes/urn-uuid.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/node_modules/uri-js/src/schemes/urn-uuid.ts b/node_modules/uri-js/src/schemes/urn-uuid.ts
new file mode 100644
index 000000000..566532920
--- /dev/null
+++ b/node_modules/uri-js/src/schemes/urn-uuid.ts
@@ -0,0 +1,36 @@
+import { URISchemeHandler, URIComponents, URIOptions } from "../uri";
+import { URNComponents } from "./urn";
+import { SCHEMES } from "../uri";
+
+export interface UUIDComponents extends URNComponents {
+ uuid?: string;
+}
+
+const UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
+const UUID_PARSE = /^[0-9A-Fa-f\-]{36}/;
+
+//RFC 4122
+const handler:URISchemeHandler<UUIDComponents, URIOptions, URNComponents> = {
+ scheme : "urn:uuid",
+
+ parse : function (urnComponents:URNComponents, options:URIOptions):UUIDComponents {
+ const uuidComponents = urnComponents as UUIDComponents;
+ uuidComponents.uuid = uuidComponents.nss;
+ uuidComponents.nss = undefined;
+
+ if (!options.tolerant && (!uuidComponents.uuid || !uuidComponents.uuid.match(UUID))) {
+ uuidComponents.error = uuidComponents.error || "UUID is not valid.";
+ }
+
+ return uuidComponents;
+ },
+
+ serialize : function (uuidComponents:UUIDComponents, options:URIOptions):URNComponents {
+ const urnComponents = uuidComponents as URNComponents;
+ //normalize UUID
+ urnComponents.nss = (uuidComponents.uuid || "").toLowerCase();
+ return urnComponents;
+ },
+};
+
+export default handler; \ No newline at end of file