utils.js 24 KB

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