Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

minpath.browser.js 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. 'use strict'
  2. // A derivative work based on:
  3. // <https://github.com/browserify/path-browserify>.
  4. // Which is licensed:
  5. //
  6. // MIT License
  7. //
  8. // Copyright (c) 2013 James Halliday
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  11. // this software and associated documentation files (the "Software"), to deal in
  12. // the Software without restriction, including without limitation the rights to
  13. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  14. // the Software, and to permit persons to whom the Software is furnished to do so,
  15. // subject to the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be included in all
  18. // copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  22. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  23. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  24. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  25. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. // A derivative work based on:
  27. //
  28. // Parts of that are extracted from Node’s internal `path` module:
  29. // <https://github.com/nodejs/node/blob/master/lib/path.js>.
  30. // Which is licensed:
  31. //
  32. // Copyright Joyent, Inc. and other Node contributors.
  33. //
  34. // Permission is hereby granted, free of charge, to any person obtaining a
  35. // copy of this software and associated documentation files (the
  36. // "Software"), to deal in the Software without restriction, including
  37. // without limitation the rights to use, copy, modify, merge, publish,
  38. // distribute, sublicense, and/or sell copies of the Software, and to permit
  39. // persons to whom the Software is furnished to do so, subject to the
  40. // following conditions:
  41. //
  42. // The above copyright notice and this permission notice shall be included
  43. // in all copies or substantial portions of the Software.
  44. //
  45. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  46. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  47. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  48. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  49. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  50. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  51. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  52. exports.basename = basename
  53. exports.dirname = dirname
  54. exports.extname = extname
  55. exports.join = join
  56. exports.sep = '/'
  57. function basename(path, ext) {
  58. var start = 0
  59. var end = -1
  60. var index
  61. var firstNonSlashEnd
  62. var seenNonSlash
  63. var extIndex
  64. if (ext !== undefined && typeof ext !== 'string') {
  65. throw new TypeError('"ext" argument must be a string')
  66. }
  67. assertPath(path)
  68. index = path.length
  69. if (ext === undefined || !ext.length || ext.length > path.length) {
  70. while (index--) {
  71. if (path.charCodeAt(index) === 47 /* `/` */) {
  72. // If we reached a path separator that was not part of a set of path
  73. // separators at the end of the string, stop now.
  74. if (seenNonSlash) {
  75. start = index + 1
  76. break
  77. }
  78. } else if (end < 0) {
  79. // We saw the first non-path separator, mark this as the end of our
  80. // path component.
  81. seenNonSlash = true
  82. end = index + 1
  83. }
  84. }
  85. return end < 0 ? '' : path.slice(start, end)
  86. }
  87. if (ext === path) {
  88. return ''
  89. }
  90. firstNonSlashEnd = -1
  91. extIndex = ext.length - 1
  92. while (index--) {
  93. if (path.charCodeAt(index) === 47 /* `/` */) {
  94. // If we reached a path separator that was not part of a set of path
  95. // separators at the end of the string, stop now.
  96. if (seenNonSlash) {
  97. start = index + 1
  98. break
  99. }
  100. } else {
  101. if (firstNonSlashEnd < 0) {
  102. // We saw the first non-path separator, remember this index in case
  103. // we need it if the extension ends up not matching.
  104. seenNonSlash = true
  105. firstNonSlashEnd = index + 1
  106. }
  107. if (extIndex > -1) {
  108. // Try to match the explicit extension.
  109. if (path.charCodeAt(index) === ext.charCodeAt(extIndex--)) {
  110. if (extIndex < 0) {
  111. // We matched the extension, so mark this as the end of our path
  112. // component
  113. end = index
  114. }
  115. } else {
  116. // Extension does not match, so our result is the entire path
  117. // component
  118. extIndex = -1
  119. end = firstNonSlashEnd
  120. }
  121. }
  122. }
  123. }
  124. if (start === end) {
  125. end = firstNonSlashEnd
  126. } else if (end < 0) {
  127. end = path.length
  128. }
  129. return path.slice(start, end)
  130. }
  131. function dirname(path) {
  132. var end
  133. var unmatchedSlash
  134. var index
  135. assertPath(path)
  136. if (!path.length) {
  137. return '.'
  138. }
  139. end = -1
  140. index = path.length
  141. // Prefix `--` is important to not run on `0`.
  142. while (--index) {
  143. if (path.charCodeAt(index) === 47 /* `/` */) {
  144. if (unmatchedSlash) {
  145. end = index
  146. break
  147. }
  148. } else if (!unmatchedSlash) {
  149. // We saw the first non-path separator
  150. unmatchedSlash = true
  151. }
  152. }
  153. return end < 0
  154. ? path.charCodeAt(0) === 47 /* `/` */
  155. ? '/'
  156. : '.'
  157. : end === 1 && path.charCodeAt(0) === 47 /* `/` */
  158. ? '//'
  159. : path.slice(0, end)
  160. }
  161. function extname(path) {
  162. var startDot = -1
  163. var startPart = 0
  164. var end = -1
  165. // Track the state of characters (if any) we see before our first dot and
  166. // after any path separator we find.
  167. var preDotState = 0
  168. var unmatchedSlash
  169. var code
  170. var index
  171. assertPath(path)
  172. index = path.length
  173. while (index--) {
  174. code = path.charCodeAt(index)
  175. if (code === 47 /* `/` */) {
  176. // If we reached a path separator that was not part of a set of path
  177. // separators at the end of the string, stop now.
  178. if (unmatchedSlash) {
  179. startPart = index + 1
  180. break
  181. }
  182. continue
  183. }
  184. if (end < 0) {
  185. // We saw the first non-path separator, mark this as the end of our
  186. // extension.
  187. unmatchedSlash = true
  188. end = index + 1
  189. }
  190. if (code === 46 /* `.` */) {
  191. // If this is our first dot, mark it as the start of our extension.
  192. if (startDot < 0) {
  193. startDot = index
  194. } else if (preDotState !== 1) {
  195. preDotState = 1
  196. }
  197. } else if (startDot > -1) {
  198. // We saw a non-dot and non-path separator before our dot, so we should
  199. // have a good chance at having a non-empty extension.
  200. preDotState = -1
  201. }
  202. }
  203. if (
  204. startDot < 0 ||
  205. end < 0 ||
  206. // We saw a non-dot character immediately before the dot.
  207. preDotState === 0 ||
  208. // The (right-most) trimmed path component is exactly `..`.
  209. (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
  210. ) {
  211. return ''
  212. }
  213. return path.slice(startDot, end)
  214. }
  215. function join() {
  216. var index = -1
  217. var joined
  218. while (++index < arguments.length) {
  219. assertPath(arguments[index])
  220. if (arguments[index]) {
  221. joined =
  222. joined === undefined
  223. ? arguments[index]
  224. : joined + '/' + arguments[index]
  225. }
  226. }
  227. return joined === undefined ? '.' : normalize(joined)
  228. }
  229. // Note: `normalize` is not exposed as `path.normalize`, so some code is
  230. // manually removed from it.
  231. function normalize(path) {
  232. var absolute
  233. var value
  234. assertPath(path)
  235. absolute = path.charCodeAt(0) === 47 /* `/` */
  236. // Normalize the path according to POSIX rules.
  237. value = normalizeString(path, !absolute)
  238. if (!value.length && !absolute) {
  239. value = '.'
  240. }
  241. if (value.length && path.charCodeAt(path.length - 1) === 47 /* / */) {
  242. value += '/'
  243. }
  244. return absolute ? '/' + value : value
  245. }
  246. // Resolve `.` and `..` elements in a path with directory names.
  247. function normalizeString(path, allowAboveRoot) {
  248. var result = ''
  249. var lastSegmentLength = 0
  250. var lastSlash = -1
  251. var dots = 0
  252. var index = -1
  253. var code
  254. var lastSlashIndex
  255. while (++index <= path.length) {
  256. if (index < path.length) {
  257. code = path.charCodeAt(index)
  258. } else if (code === 47 /* `/` */) {
  259. break
  260. } else {
  261. code = 47 /* `/` */
  262. }
  263. if (code === 47 /* `/` */) {
  264. if (lastSlash === index - 1 || dots === 1) {
  265. // Empty.
  266. } else if (lastSlash !== index - 1 && dots === 2) {
  267. if (
  268. result.length < 2 ||
  269. lastSegmentLength !== 2 ||
  270. result.charCodeAt(result.length - 1) !== 46 /* `.` */ ||
  271. result.charCodeAt(result.length - 2) !== 46 /* `.` */
  272. ) {
  273. if (result.length > 2) {
  274. lastSlashIndex = result.lastIndexOf('/')
  275. /* istanbul ignore else - No clue how to cover it. */
  276. if (lastSlashIndex !== result.length - 1) {
  277. if (lastSlashIndex < 0) {
  278. result = ''
  279. lastSegmentLength = 0
  280. } else {
  281. result = result.slice(0, lastSlashIndex)
  282. lastSegmentLength = result.length - 1 - result.lastIndexOf('/')
  283. }
  284. lastSlash = index
  285. dots = 0
  286. continue
  287. }
  288. } else if (result.length) {
  289. result = ''
  290. lastSegmentLength = 0
  291. lastSlash = index
  292. dots = 0
  293. continue
  294. }
  295. }
  296. if (allowAboveRoot) {
  297. result = result.length ? result + '/..' : '..'
  298. lastSegmentLength = 2
  299. }
  300. } else {
  301. if (result.length) {
  302. result += '/' + path.slice(lastSlash + 1, index)
  303. } else {
  304. result = path.slice(lastSlash + 1, index)
  305. }
  306. lastSegmentLength = index - lastSlash - 1
  307. }
  308. lastSlash = index
  309. dots = 0
  310. } else if (code === 46 /* `.` */ && dots > -1) {
  311. dots++
  312. } else {
  313. dots = -1
  314. }
  315. }
  316. return result
  317. }
  318. function assertPath(path) {
  319. if (typeof path !== 'string') {
  320. throw new TypeError(
  321. 'Path must be a string. Received ' + JSON.stringify(path)
  322. )
  323. }
  324. }