utils.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /* eslint-disable */
  2. const logUtils = require('./log.js')
  3. const hasProxy = typeof Proxy !== 'undefined'
  4. let _Proxy = function () {}
  5. if (hasProxy) {
  6. _Proxy = Proxy
  7. }
  8. module.exports = {
  9. ...logUtils,
  10. nextUid(len = 8) {
  11. return Math.random()
  12. .toString(36)
  13. .substr(len + 1)
  14. },
  15. parseSelector(sel) {
  16. let ret = sel
  17. if (sel.indexOf('>>>') !== -1) {
  18. console.warn('支付宝不支持跨自定义组件的后代选择器,已降级')
  19. const arr = sel.split('>>>')
  20. ret = arr[arr.length - 1].trim()
  21. }
  22. return ret
  23. },
  24. /**
  25. * defineGetter
  26. */
  27. defineGetter(obj = {}, descObj = {}, cb = () => {}) {
  28. if (!hasProxy) {
  29. return obj
  30. }
  31. return new _Proxy(obj, {
  32. get(target, attr) {
  33. if (
  34. typeof attr === 'string' &&
  35. descObj[attr] &&
  36. descObj[attr].type === 0
  37. ) {
  38. cb && cb(target, attr)
  39. }
  40. return target[attr]
  41. },
  42. })
  43. },
  44. /**
  45. * sourceObj : 要操作对象
  46. * wxAttr: 微信key值
  47. * alipayAttr: 支付宝key值
  48. **/
  49. objectMap(sourceObj = {}, wxAttr, alipayAttr) {
  50. if (!hasProxy) {
  51. Object.defineProperty(sourceObj, wxAttr, {
  52. get() {
  53. return sourceObj[alipayAttr]
  54. },
  55. })
  56. return sourceObj
  57. }
  58. return new _Proxy(sourceObj, {
  59. get(target, attr) {
  60. if (attr === wxAttr) {
  61. return target[alipayAttr]
  62. }
  63. },
  64. })
  65. },
  66. // 类型转换
  67. changeType(str) {
  68. const hexA = new Array(0)
  69. if (typeof attr === 'string') {
  70. // 十六进制字符串转字节数组
  71. let pos = 0
  72. let len = str.length
  73. if (len % 2 !== 0) {
  74. return null
  75. }
  76. len /= 2
  77. for (let i = 0; i < len; i++) {
  78. const s = str.substr(pos, 2)
  79. const v = parseInt(s, 16)
  80. hexA.push(v)
  81. pos += 2
  82. }
  83. return hexA
  84. }
  85. },
  86. // https://github.com/wandergis/coordtransform/blob/master/index.js
  87. gcj02towgs84(_lng, _lat) {
  88. const lat = +_lat
  89. const lng = +_lng
  90. const ee = 0.00669342162296594323
  91. const a = 6378245.0
  92. if (out_of_china(lng, lat)) {
  93. return [lng, lat]
  94. } else {
  95. let dlat = transformlat(lng - 105.0, lat - 35.0)
  96. let dlng = transformlng(lng - 105.0, lat - 35.0)
  97. const radlat = (lat / 180.0) * Math.PI
  98. let magic = Math.sin(radlat)
  99. magic = 1 - ee * magic * magic
  100. const sqrtmagic = Math.sqrt(magic)
  101. dlat = (dlat * 180.0) / (((a * (1 - ee)) / (magic * sqrtmagic)) * Math.PI)
  102. dlng = (dlng * 180.0) / ((a / sqrtmagic) * Math.cos(radlat) * Math.PI)
  103. const mglat = lat + dlat
  104. const mglng = lng + dlng
  105. return [lng * 2 - mglng, lat * 2 - mglat]
  106. }
  107. },
  108. ab2hex(buffer) {
  109. const hexArr = Array.prototype.map.call(new Uint8Array(buffer), (bit) => {
  110. return `00${bit.toString(16)}`.slice(-2)
  111. })
  112. return hexArr.join('')
  113. },
  114. /**
  115. * change attr for object
  116. * replace attr by newAttr
  117. */
  118. changeObjAttr(obj = {}, attr, newAttr) {
  119. if (obj[attr] !== undefined) {
  120. obj[newAttr] = obj[attr]
  121. delete obj[attr]
  122. } else {
  123. console.warn(`${attr} attribute is missing!`)
  124. }
  125. return obj
  126. },
  127. fnAppClass,
  128. browserPath,
  129. mapAuthSetting,
  130. }
  131. function out_of_china(lng, lat) {
  132. // 纬度3.86~53.55,经度73.66~135.05
  133. return !(lng > 73.66 && lng < 135.05 && lat > 3.86 && lat < 53.55)
  134. }
  135. function transformlat(lng, lat) {
  136. let ret =
  137. -100.0 +
  138. 2.0 * lng +
  139. 3.0 * lat +
  140. 0.2 * lat * lat +
  141. 0.1 * lng * lat +
  142. 0.2 * Math.sqrt(Math.abs(lng))
  143. ret +=
  144. ((20.0 * Math.sin(6.0 * lng * Math.PI) +
  145. 20.0 * Math.sin(2.0 * lng * Math.PI)) *
  146. 2.0) /
  147. 3.0
  148. ret +=
  149. ((20.0 * Math.sin(lat * Math.PI) + 40.0 * Math.sin((lat / 3.0) * Math.PI)) *
  150. 2.0) /
  151. 3.0
  152. ret +=
  153. ((160.0 * Math.sin((lat / 12.0) * Math.PI) +
  154. 320 * Math.sin((lat * Math.PI) / 30.0)) *
  155. 2.0) /
  156. 3.0
  157. return ret
  158. }
  159. function transformlng(lng, lat) {
  160. let ret =
  161. 300.0 +
  162. lng +
  163. 2.0 * lat +
  164. 0.1 * lng * lng +
  165. 0.1 * lng * lat +
  166. 0.1 * Math.sqrt(Math.abs(lng))
  167. ret +=
  168. ((20.0 * Math.sin(6.0 * lng * Math.PI) +
  169. 20.0 * Math.sin(2.0 * lng * Math.PI)) *
  170. 2.0) /
  171. 3.0
  172. ret +=
  173. ((20.0 * Math.sin(lng * Math.PI) + 40.0 * Math.sin((lng / 3.0) * Math.PI)) *
  174. 2.0) /
  175. 3.0
  176. ret +=
  177. ((150.0 * Math.sin((lng / 12.0) * Math.PI) +
  178. 300.0 * Math.sin((lng / 30.0) * Math.PI)) *
  179. 2.0) /
  180. 3.0
  181. return ret
  182. }
  183. function fnAppClass() {
  184. const fn = {
  185. $data: {},
  186. add(key, cb = () => {}) {
  187. fn.$data[key] = fn.$data[key] || []
  188. fn.$data[key].push(cb)
  189. return fn
  190. },
  191. insert(key, cb = () => {}) {
  192. fn.$data[key] = fn.$data[key] || []
  193. fn.$data[key].unshift(cb)
  194. },
  195. getFn(key) {
  196. return fn.$data[key]
  197. },
  198. bind(key, ctx = {}) {
  199. fn.$data[key] = fn.$data[key] || []
  200. fn.add(key, ctx[key])
  201. ctx[key] = function (...params) {
  202. const self = this
  203. fn.getFn(key).forEach((cb) => {
  204. cb.apply(self, params)
  205. })
  206. }
  207. },
  208. }
  209. return fn
  210. }
  211. function assertPath(path) {
  212. if (typeof path !== 'string') {
  213. throw new TypeError(
  214. `Path must be a string. Received ${JSON.stringify(path)}`
  215. )
  216. }
  217. }
  218. // Resolves . and .. elements in a path with directory names
  219. function normalizeStringPosix(path, allowAboveRoot) {
  220. let res = ''
  221. let lastSegmentLength = 0
  222. let lastSlash = -1
  223. let dots = 0
  224. let code
  225. for (let i = 0; i <= path.length; ++i) {
  226. if (i < path.length) {
  227. code = path.charCodeAt(i)
  228. } else if (code === 47 /* /*/) {
  229. break
  230. } else {
  231. code = 47 /* /*/
  232. }
  233. if (code === 47 /* /*/) {
  234. if (lastSlash === i - 1 || dots === 1) {
  235. // NOOP
  236. } else if (lastSlash !== i - 1 && dots === 2) {
  237. if (
  238. res.length < 2 ||
  239. lastSegmentLength !== 2 ||
  240. res.charCodeAt(res.length - 1) !== 46 /* .*/ ||
  241. res.charCodeAt(res.length - 2) !== 46 /* .*/
  242. ) {
  243. if (res.length > 2) {
  244. const lastSlashIndex = res.lastIndexOf('/')
  245. if (lastSlashIndex !== res.length - 1) {
  246. if (lastSlashIndex === -1) {
  247. res = ''
  248. lastSegmentLength = 0
  249. } else {
  250. res = res.slice(0, lastSlashIndex)
  251. lastSegmentLength = res.length - 1 - res.lastIndexOf('/')
  252. }
  253. lastSlash = i
  254. dots = 0
  255. continue
  256. }
  257. } else if (res.length === 2 || res.length === 1) {
  258. res = ''
  259. lastSegmentLength = 0
  260. lastSlash = i
  261. dots = 0
  262. continue
  263. }
  264. }
  265. if (allowAboveRoot) {
  266. if (res.length > 0) {
  267. res += '/..'
  268. } else {
  269. res = '..'
  270. }
  271. lastSegmentLength = 2
  272. }
  273. } else {
  274. if (res.length > 0) {
  275. res += `/${path.slice(lastSlash + 1, i)}`
  276. } else {
  277. res = path.slice(lastSlash + 1, i)
  278. }
  279. lastSegmentLength = i - lastSlash - 1
  280. }
  281. lastSlash = i
  282. dots = 0
  283. } else if (code === 46 /* .*/ && dots !== -1) {
  284. ++dots
  285. } else {
  286. dots = -1
  287. }
  288. }
  289. return res
  290. }
  291. function _format(sep, pathObject) {
  292. const dir = pathObject.dir || pathObject.root
  293. const base =
  294. pathObject.base || (pathObject.name || '') + (pathObject.ext || '')
  295. if (!dir) {
  296. return base
  297. }
  298. if (dir === pathObject.root) {
  299. return dir + base
  300. }
  301. return dir + sep + base
  302. }
  303. const posix = {
  304. // path.resolve([from ...], to)
  305. resolve: function resolve(...args) {
  306. let resolvedPath = ''
  307. let resolvedAbsolute = false
  308. let cwd
  309. for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
  310. let path
  311. if (i >= 0) {
  312. path = args[i]
  313. } else {
  314. if (cwd === undefined) {
  315. cwd = process.cwd()
  316. }
  317. path = cwd
  318. }
  319. assertPath(path)
  320. // Skip empty entries
  321. if (path.length === 0) {
  322. continue
  323. }
  324. resolvedPath = `${path}/${resolvedPath}`
  325. resolvedAbsolute = path.charCodeAt(0) === 47 /* /*/
  326. }
  327. // At this point the path should be resolved to a full absolute path, but
  328. // handle relative paths to be safe (might happen when process.cwd() fails)
  329. // Normalize the path
  330. resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute)
  331. if (resolvedAbsolute) {
  332. if (resolvedPath.length > 0) {
  333. return `/${resolvedPath}`
  334. }
  335. return '/'
  336. } else if (resolvedPath.length > 0) {
  337. return resolvedPath
  338. }
  339. return '.'
  340. },
  341. normalize: function normalize(path) {
  342. assertPath(path)
  343. if (path.length === 0) {
  344. return '.'
  345. }
  346. const isAbsolute = path.charCodeAt(0) === 47 /* /*/
  347. const trailingSeparator = path.charCodeAt(path.length - 1) === 47 /* /*/
  348. // Normalize the path
  349. path = normalizeStringPosix(path, !isAbsolute)
  350. if (path.length === 0 && !isAbsolute) {
  351. path = '.'
  352. }
  353. if (path.length > 0 && trailingSeparator) {
  354. path += '/'
  355. }
  356. if (isAbsolute) {
  357. return `/${path}`
  358. }
  359. return path
  360. },
  361. isAbsolute: function isAbsolute(path) {
  362. assertPath(path)
  363. return path.length > 0 && path.charCodeAt(0) === 47 /* /*/
  364. },
  365. join: function join(...p) {
  366. if (p.length === 0) {
  367. return '.'
  368. }
  369. let joined
  370. for (let i = 0; i < p.length; ++i) {
  371. const arg = p[i]
  372. assertPath(arg)
  373. if (arg.length > 0) {
  374. if (joined === undefined) {
  375. joined = arg
  376. } else {
  377. joined += `/${arg}`
  378. }
  379. }
  380. }
  381. if (joined === undefined) {
  382. return '.'
  383. }
  384. return posix.normalize(joined)
  385. },
  386. relative: function relative(from, to) {
  387. assertPath(from)
  388. assertPath(to)
  389. if (from === to) {
  390. return ''
  391. }
  392. from = posix.resolve(from)
  393. to = posix.resolve(to)
  394. if (from === to) {
  395. return ''
  396. }
  397. // Trim any leading backslashes
  398. let fromStart = 1
  399. for (; fromStart < from.length; ++fromStart) {
  400. if (from.charCodeAt(fromStart) !== 47 /* /*/) {
  401. break
  402. }
  403. }
  404. const fromEnd = from.length
  405. const fromLen = fromEnd - fromStart
  406. // Trim any leading backslashes
  407. let toStart = 1
  408. for (; toStart < to.length; ++toStart) {
  409. if (to.charCodeAt(toStart) !== 47 /* /*/) {
  410. break
  411. }
  412. }
  413. const toEnd = to.length
  414. const toLen = toEnd - toStart
  415. // Compare paths to find the longest common path from root
  416. const length = fromLen < toLen ? fromLen : toLen
  417. let lastCommonSep = -1
  418. let i = 0
  419. for (; i <= length; ++i) {
  420. if (i === length) {
  421. if (toLen > length) {
  422. if (to.charCodeAt(toStart + i) === 47 /* /*/) {
  423. // We get here if `from` is the exact base path for `to`.
  424. // For example: from='/foo/bar'; to='/foo/bar/baz'
  425. return to.slice(toStart + i + 1)
  426. } else if (i === 0) {
  427. // We get here if `from` is the root
  428. // For example: from='/'; to='/foo'
  429. return to.slice(toStart + i)
  430. }
  431. } else if (fromLen > length) {
  432. if (from.charCodeAt(fromStart + i) === 47 /* /*/) {
  433. // We get here if `to` is the exact base path for `from`.
  434. // For example: from='/foo/bar/baz'; to='/foo/bar'
  435. lastCommonSep = i
  436. } else if (i === 0) {
  437. // We get here if `to` is the root.
  438. // For example: from='/foo'; to='/'
  439. lastCommonSep = 0
  440. }
  441. }
  442. break
  443. }
  444. const fromCode = from.charCodeAt(fromStart + i)
  445. const toCode = to.charCodeAt(toStart + i)
  446. if (fromCode !== toCode) {
  447. break
  448. } else if (fromCode === 47 /* /*/) {
  449. lastCommonSep = i
  450. }
  451. }
  452. let out = ''
  453. // Generate the relative path based on the path difference between `to`
  454. // and `from`
  455. for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
  456. if (i === fromEnd || from.charCodeAt(i) === 47 /* /*/) {
  457. if (out.length === 0) {
  458. out += '..'
  459. } else {
  460. out += '/..'
  461. }
  462. }
  463. }
  464. // Lastly, append the rest of the destination (`to`) path that comes after
  465. // the common path parts
  466. if (out.length > 0) {
  467. return out + to.slice(toStart + lastCommonSep)
  468. }
  469. toStart += lastCommonSep
  470. if (to.charCodeAt(toStart) === 47 /* /*/) {
  471. ++toStart
  472. }
  473. return to.slice(toStart)
  474. },
  475. _makeLong: function _makeLong(path) {
  476. return path
  477. },
  478. dirname: function dirname(path) {
  479. assertPath(path)
  480. if (path.length === 0) {
  481. return '.'
  482. }
  483. let code = path.charCodeAt(0)
  484. const hasRoot = code === 47 /* /*/
  485. let end = -1
  486. let matchedSlash = true
  487. for (let i = path.length - 1; i >= 1; --i) {
  488. code = path.charCodeAt(i)
  489. if (code === 47 /* /*/) {
  490. if (!matchedSlash) {
  491. end = i
  492. break
  493. }
  494. } else {
  495. // We saw the first non-path separator
  496. matchedSlash = false
  497. }
  498. }
  499. if (end === -1) {
  500. return hasRoot ? '/' : '.'
  501. }
  502. if (hasRoot && end === 1) {
  503. return '//'
  504. }
  505. return path.slice(0, end)
  506. },
  507. basename: function basename(path, ext) {
  508. if (ext !== undefined && typeof ext !== 'string') {
  509. throw new TypeError('"ext" argument must be a string')
  510. }
  511. assertPath(path)
  512. let start = 0
  513. let end = -1
  514. let matchedSlash = true
  515. let i
  516. if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
  517. if (ext.length === path.length && ext === path) {
  518. return ''
  519. }
  520. let extIdx = ext.length - 1
  521. let firstNonSlashEnd = -1
  522. for (i = path.length - 1; i >= 0; --i) {
  523. const code = path.charCodeAt(i)
  524. if (code === 47 /* /*/) {
  525. // If we reached a path separator that was not part of a set of path
  526. // separators at the end of the string, stop now
  527. if (!matchedSlash) {
  528. start = i + 1
  529. break
  530. }
  531. } else {
  532. if (firstNonSlashEnd === -1) {
  533. // We saw the first non-path separator, remember this index in case
  534. // we need it if the extension ends up not matching
  535. matchedSlash = false
  536. firstNonSlashEnd = i + 1
  537. }
  538. if (extIdx >= 0) {
  539. // Try to match the explicit extension
  540. if (code === ext.charCodeAt(extIdx)) {
  541. if (--extIdx === -1) {
  542. // We matched the extension, so mark this as the end of our path
  543. // component
  544. end = i
  545. }
  546. } else {
  547. // Extension does not match, so our result is the entire path
  548. // component
  549. extIdx = -1
  550. end = firstNonSlashEnd
  551. }
  552. }
  553. }
  554. }
  555. if (start === end) {
  556. end = firstNonSlashEnd
  557. } else if (end === -1) {
  558. end = path.length
  559. }
  560. return path.slice(start, end)
  561. }
  562. for (i = path.length - 1; i >= 0; --i) {
  563. if (path.charCodeAt(i) === 47 /* /*/) {
  564. // If we reached a path separator that was not part of a set of path
  565. // separators at the end of the string, stop now
  566. if (!matchedSlash) {
  567. start = i + 1
  568. break
  569. }
  570. } else if (end === -1) {
  571. // We saw the first non-path separator, mark this as the end of our
  572. // path component
  573. matchedSlash = false
  574. end = i + 1
  575. }
  576. }
  577. if (end === -1) {
  578. return ''
  579. }
  580. return path.slice(start, end)
  581. },
  582. extname: function extname(path) {
  583. assertPath(path)
  584. let startDot = -1
  585. let startPart = 0
  586. let end = -1
  587. let matchedSlash = true
  588. // Track the state of characters (if any) we see before our first dot and
  589. // after any path separator we find
  590. let preDotState = 0
  591. for (let i = path.length - 1; i >= 0; --i) {
  592. const code = path.charCodeAt(i)
  593. if (code === 47 /* /*/) {
  594. // If we reached a path separator that was not part of a set of path
  595. // separators at the end of the string, stop now
  596. if (!matchedSlash) {
  597. startPart = i + 1
  598. break
  599. }
  600. continue
  601. }
  602. if (end === -1) {
  603. // We saw the first non-path separator, mark this as the end of our
  604. // extension
  605. matchedSlash = false
  606. end = i + 1
  607. }
  608. if (code === 46 /* .*/) {
  609. // If this is our first dot, mark it as the start of our extension
  610. if (startDot === -1) {
  611. startDot = i
  612. } else if (preDotState !== 1) {
  613. preDotState = 1
  614. }
  615. } else if (startDot !== -1) {
  616. // We saw a non-dot and non-path separator before our dot, so we should
  617. // have a good chance at having a non-empty extension
  618. preDotState = -1
  619. }
  620. }
  621. if (
  622. startDot === -1 ||
  623. end === -1 ||
  624. // We saw a non-dot character immediately before the dot
  625. preDotState === 0 ||
  626. // The (right-most) trimmed path component is exactly '..'
  627. (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
  628. ) {
  629. return ''
  630. }
  631. return path.slice(startDot, end)
  632. },
  633. format: function format(pathObject) {
  634. if (pathObject === null || typeof pathObject !== 'object') {
  635. throw new TypeError(
  636. `The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`
  637. )
  638. }
  639. return _format('/', pathObject)
  640. },
  641. parse: function parse(path) {
  642. assertPath(path)
  643. const ret = { root: '', dir: '', base: '', ext: '', name: '' }
  644. if (path.length === 0) {
  645. return ret
  646. }
  647. let code = path.charCodeAt(0)
  648. const isAbsolute = code === 47 /* /*/
  649. let start
  650. if (isAbsolute) {
  651. ret.root = '/'
  652. start = 1
  653. } else {
  654. start = 0
  655. }
  656. let startDot = -1
  657. let startPart = 0
  658. let end = -1
  659. let matchedSlash = true
  660. let i = path.length - 1
  661. // Track the state of characters (if any) we see before our first dot and
  662. // after any path separator we find
  663. let preDotState = 0
  664. // Get non-dir info
  665. for (; i >= start; --i) {
  666. code = path.charCodeAt(i)
  667. if (code === 47 /* /*/) {
  668. // If we reached a path separator that was not part of a set of path
  669. // separators at the end of the string, stop now
  670. if (!matchedSlash) {
  671. startPart = i + 1
  672. break
  673. }
  674. continue
  675. }
  676. if (end === -1) {
  677. // We saw the first non-path separator, mark this as the end of our
  678. // extension
  679. matchedSlash = false
  680. end = i + 1
  681. }
  682. if (code === 46 /* .*/) {
  683. // If this is our first dot, mark it as the start of our extension
  684. if (startDot === -1) {
  685. startDot = i
  686. } else if (preDotState !== 1) {
  687. preDotState = 1
  688. }
  689. } else if (startDot !== -1) {
  690. // We saw a non-dot and non-path separator before our dot, so we should
  691. // have a good chance at having a non-empty extension
  692. preDotState = -1
  693. }
  694. }
  695. if (
  696. startDot === -1 ||
  697. end === -1 ||
  698. // We saw a non-dot character immediately before the dot
  699. preDotState === 0 ||
  700. // The (right-most) trimmed path component is exactly '..'
  701. (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
  702. ) {
  703. if (end !== -1) {
  704. if (startPart === 0 && isAbsolute) {
  705. ret.base = path.slice(1, end)
  706. ret.name = path.slice(1, end)
  707. } else {
  708. ret.base = path.slice(startPart, end)
  709. ret.name = path.slice(startPart, end)
  710. }
  711. }
  712. } else {
  713. if (startPart === 0 && isAbsolute) {
  714. ret.name = path.slice(1, startDot)
  715. ret.base = path.slice(1, end)
  716. } else {
  717. ret.name = path.slice(startPart, startDot)
  718. ret.base = path.slice(startPart, end)
  719. }
  720. ret.ext = path.slice(startDot, end)
  721. }
  722. if (startPart > 0) {
  723. ret.dir = path.slice(0, startPart - 1)
  724. } else if (isAbsolute) {
  725. ret.dir = '/'
  726. }
  727. return ret
  728. },
  729. sep: '/',
  730. delimiter: ':',
  731. win32: null,
  732. posix: null,
  733. }
  734. posix.posix = posix
  735. function browserPath() {
  736. return posix
  737. }
  738. function mapAuthSetting(obj) {
  739. const keys = [
  740. ['scope.userLocation', 'location'],
  741. ['scope.writePhotosAlbum', 'album'],
  742. ['scope.camera', 'camera'],
  743. ['scope.userInfo', 'userInfo'],
  744. ['scope.address', 'aliaddress'],
  745. ['scope.werun', 'alipaysports'],
  746. ]
  747. const authSetting = {}
  748. keys.forEach((item) => {
  749. const value = obj[item[1]]
  750. if (typeof value !== 'undefined') {
  751. authSetting[item[0]] = value
  752. }
  753. })
  754. return authSetting
  755. }