@umijs/route-utils
Advanced tools
Comparing version 1.0.17 to 1.0.18
@@ -1,3 +0,4 @@ | ||
import pathToRegexp from 'path-to-regexp'; | ||
import { pathToRegexp } from '@qixian.cs/path-to-regexp'; | ||
import getFlatMenu from '../getFlatMenus/getFlatMenus'; | ||
import { isUrl } from '../transformRoute/transformRoute'; | ||
/** | ||
@@ -40,5 +41,5 @@ * a-b-c | ||
if (item !== '/' && item) { | ||
if (item !== '/' && item && !isUrl(item)) { | ||
// /a | ||
if (pathToRegexp("".concat(item)).test(path)) { | ||
if (pathToRegexp("".concat(item), []).test(path)) { | ||
return true; | ||
@@ -45,0 +46,0 @@ } // /a/b/b |
@@ -0,1 +1,39 @@ | ||
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); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } | ||
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
@@ -26,2 +64,3 @@ | ||
import hash from 'hash.js'; | ||
import { pathToRegexp } from '@qixian.cs/path-to-regexp'; | ||
/* eslint no-useless-escape:0 import/prefer-default-export:0 */ | ||
@@ -52,4 +91,4 @@ | ||
return "/".concat(hash.sha256().update(JSON.stringify(item)).digest('hex')); | ||
} catch (error) {} // dom some thing | ||
// 要是还是不行,返回一个随机值 | ||
} catch (error) {// dom some thing | ||
} // 要是还是不行,返回一个随机值 | ||
@@ -289,2 +328,49 @@ | ||
/** | ||
* support pathToRegexp get string | ||
*/ | ||
var RoutesMap = /*#__PURE__*/function (_Map) { | ||
_inherits(RoutesMap, _Map); | ||
var _super = _createSuper(RoutesMap); | ||
function RoutesMap() { | ||
_classCallCheck(this, RoutesMap); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(RoutesMap, [{ | ||
key: "get", | ||
value: function get(pathname) { | ||
var routeValue; // eslint-disable-next-line no-restricted-syntax | ||
var _iterator = _createForOfIteratorHelper(this.entries()), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _step$value = _slicedToArray(_step.value, 2), | ||
key = _step$value[0], | ||
value = _step$value[1]; | ||
if (!isUrl(key) && pathToRegexp(key, []).test(pathname)) { | ||
routeValue = value; | ||
break; | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return routeValue; | ||
} | ||
}]); | ||
return RoutesMap; | ||
}( /*#__PURE__*/_wrapNativeSuper(Map)); | ||
/** | ||
* 获取面包屑映射 | ||
@@ -297,3 +383,3 @@ * @param MenuDataItem[] menuData 菜单配置 | ||
// Map is used to ensure the order of keys | ||
var routerMap = new Map(); | ||
var routerMap = new RoutesMap(); | ||
@@ -300,0 +386,0 @@ var flattenMenuData = function flattenMenuData(data, parent) { |
@@ -8,6 +8,8 @@ "use strict"; | ||
var _pathToRegexp = _interopRequireDefault(require("path-to-regexp")); | ||
var _pathToRegexp = require("@qixian.cs/path-to-regexp"); | ||
var _getFlatMenus = _interopRequireDefault(require("../getFlatMenus/getFlatMenus")); | ||
var _transformRoute = require("../transformRoute/transformRoute"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -54,5 +56,5 @@ | ||
if (item !== '/' && item) { | ||
if (item !== '/' && item && !(0, _transformRoute.isUrl)(item)) { | ||
// /a | ||
if ((0, _pathToRegexp.default)("".concat(item)).test(path)) { | ||
if ((0, _pathToRegexp.pathToRegexp)("".concat(item), []).test(path)) { | ||
return true; | ||
@@ -62,3 +64,3 @@ } // /a/b/b | ||
if ((0, _pathToRegexp.default)("".concat(item, "(.*)")).test(path)) { | ||
if ((0, _pathToRegexp.pathToRegexp)("".concat(item, "(.*)")).test(path)) { | ||
return true; | ||
@@ -65,0 +67,0 @@ } |
@@ -15,4 +15,44 @@ "use strict"; | ||
var _pathToRegexp = require("@qixian.cs/path-to-regexp"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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); } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } | ||
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
@@ -69,4 +109,4 @@ | ||
return "/".concat(_hash.default.sha256().update(JSON.stringify(item)).digest('hex')); | ||
} catch (error) {} // dom some thing | ||
// 要是还是不行,返回一个随机值 | ||
} catch (error) {// dom some thing | ||
} // 要是还是不行,返回一个随机值 | ||
@@ -309,2 +349,49 @@ | ||
/** | ||
* support pathToRegexp get string | ||
*/ | ||
var RoutesMap = /*#__PURE__*/function (_Map) { | ||
_inherits(RoutesMap, _Map); | ||
var _super = _createSuper(RoutesMap); | ||
function RoutesMap() { | ||
_classCallCheck(this, RoutesMap); | ||
return _super.apply(this, arguments); | ||
} | ||
_createClass(RoutesMap, [{ | ||
key: "get", | ||
value: function get(pathname) { | ||
var routeValue; // eslint-disable-next-line no-restricted-syntax | ||
var _iterator = _createForOfIteratorHelper(this.entries()), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _step$value = _slicedToArray(_step.value, 2), | ||
key = _step$value[0], | ||
value = _step$value[1]; | ||
if (!isUrl(key) && (0, _pathToRegexp.pathToRegexp)(key, []).test(pathname)) { | ||
routeValue = value; | ||
break; | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
return routeValue; | ||
} | ||
}]); | ||
return RoutesMap; | ||
}( /*#__PURE__*/_wrapNativeSuper(Map)); | ||
/** | ||
* 获取面包屑映射 | ||
@@ -317,3 +404,3 @@ * @param MenuDataItem[] menuData 菜单配置 | ||
// Map is used to ensure the order of keys | ||
var routerMap = new Map(); | ||
var routerMap = new RoutesMap(); | ||
@@ -320,0 +407,0 @@ var flattenMenuData = function flattenMenuData(data, parent) { |
{ | ||
"name": "@umijs/route-utils", | ||
"version": "1.0.17", | ||
"version": "1.0.18", | ||
"description": "Quickly process the routing of umi", | ||
@@ -24,3 +24,3 @@ "main": "lib/index.js", | ||
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty", | ||
"tsc": "tsc", | ||
"tsc": "tsc --noEmit", | ||
"prepublishOnly": "npm run test && npm run build && np --no-cleanup --yolo --no-publish --any-branch" | ||
@@ -32,3 +32,3 @@ }, | ||
"@umijs/fabric": "^2.0.8", | ||
"eslint": "^6.8.0", | ||
"eslint": "^7.0.0", | ||
"father": "^2.16.0", | ||
@@ -41,7 +41,7 @@ "np": "^6.2.3", | ||
"dependencies": { | ||
"@qixian.cs/path-to-regexp": "^6.1.0", | ||
"hash.js": "^1.1.7", | ||
"lodash.isequal": "^4.5.0", | ||
"memoize-one": "^5.1.1", | ||
"path-to-regexp": "2.4.0" | ||
"memoize-one": "^5.1.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
252334
53
3487
+ Added@qixian.cs/path-to-regexp@6.1.0(transitive)
- Removedpath-to-regexp@2.4.0
- Removedpath-to-regexp@2.4.0(transitive)