Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / node_modules / @protobufjs / path / index.js
diff --git a/legacy-libs/grpc-cloned/node_modules/@protobufjs/path/index.js b/legacy-libs/grpc-cloned/node_modules/@protobufjs/path/index.js
new file mode 100644 (file)
index 0000000..1ea7b17
--- /dev/null
@@ -0,0 +1,65 @@
+"use strict";\r
+\r
+/**\r
+ * A minimal path module to resolve Unix, Windows and URL paths alike.\r
+ * @memberof util\r
+ * @namespace\r
+ */\r
+var path = exports;\r
+\r
+var isAbsolute =\r
+/**\r
+ * Tests if the specified path is absolute.\r
+ * @param {string} path Path to test\r
+ * @returns {boolean} `true` if path is absolute\r
+ */\r
+path.isAbsolute = function isAbsolute(path) {\r
+    return /^(?:\/|\w+:)/.test(path);\r
+};\r
+\r
+var normalize =\r
+/**\r
+ * Normalizes the specified path.\r
+ * @param {string} path Path to normalize\r
+ * @returns {string} Normalized path\r
+ */\r
+path.normalize = function normalize(path) {\r
+    path = path.replace(/\\/g, "/")\r
+               .replace(/\/{2,}/g, "/");\r
+    var parts    = path.split("/"),\r
+        absolute = isAbsolute(path),\r
+        prefix   = "";\r
+    if (absolute)\r
+        prefix = parts.shift() + "/";\r
+    for (var i = 0; i < parts.length;) {\r
+        if (parts[i] === "..") {\r
+            if (i > 0 && parts[i - 1] !== "..")\r
+                parts.splice(--i, 2);\r
+            else if (absolute)\r
+                parts.splice(i, 1);\r
+            else\r
+                ++i;\r
+        } else if (parts[i] === ".")\r
+            parts.splice(i, 1);\r
+        else\r
+            ++i;\r
+    }\r
+    return prefix + parts.join("/");\r
+};\r
+\r
+/**\r
+ * Resolves the specified include path against the specified origin path.\r
+ * @param {string} originPath Path to the origin file\r
+ * @param {string} includePath Include path relative to origin path\r
+ * @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized\r
+ * @returns {string} Path to the include file\r
+ */\r
+path.resolve = function resolve(originPath, includePath, alreadyNormalized) {\r
+    if (!alreadyNormalized)\r
+        includePath = normalize(includePath);\r
+    if (isAbsolute(includePath))\r
+        return includePath;\r
+    if (!alreadyNormalized)\r
+        originPath = normalize(originPath);\r
+    return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;\r
+};\r