Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-react-router-breadcrumbs

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-react-router-breadcrumbs - npm Package Compare versions

Comparing version 3.2.1 to 4.0.0

tsconfig.eslint.json

24

dist/cjs/index.js

@@ -6,3 +6,3 @@ 'use strict';

var React = require('react');
var reactRouter = require('react-router');
var reactRouterDom = require('react-router-dom');

@@ -141,3 +141,3 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

key: componentProps.key
}, Breadcrumb) : /*#__PURE__*/React__default['default'].createElement(Breadcrumb, Object.assign({}, componentProps))
}, Breadcrumb) : /*#__PURE__*/React__default["default"].createElement(Breadcrumb, Object.assign({}, componentProps))
});

@@ -151,3 +151,3 @@ };

defaultFormatter = _ref2.defaultFormatter;
var match = reactRouter.matchPath({
var match = reactRouterDom.matchPath({
end: true,

@@ -174,3 +174,3 @@ path: pathSection

var getIsPathExcluded = function getIsPathExcluded(path) {
return reactRouter.matchPath({
return reactRouterDom.matchPath({
path: path,

@@ -201,3 +201,3 @@ end: true

props = route.props;
var match = reactRouter.matchPath({
var match = reactRouterDom.matchPath({
path: path,

@@ -283,3 +283,3 @@ end: true,

routes: routes || [],
location: reactRouter.useLocation(),
location: reactRouterDom.useLocation(),
options: options

@@ -295,8 +295,8 @@ });

var routes = [];
React__default['default'].Children.forEach(children, function (element) {
if (! /*#__PURE__*/React__default['default'].isValidElement(element)) {
React__default["default"].Children.forEach(children, function (element) {
if (! /*#__PURE__*/React__default["default"].isValidElement(element)) {
return;
}
if (element.type === React__default['default'].Fragment) {
if (element.type === React__default["default"].Fragment) {
routes.push.apply(routes, createRoutesFromChildren(element.props.children));

@@ -306,3 +306,3 @@ return;

invariant(element.type === reactRouter.Route, "[".concat(typeof element.type === 'string' ? element.type : element.type.name, "] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>"));
invariant(element.type === reactRouterDom.Route, "[".concat(typeof element.type === 'string' ? element.type : element.type.name, "] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>"));
var route = {

@@ -324,8 +324,8 @@ caseSensitive: element.props.caseSensitive,

}
var BreadCrumbRoute = reactRouter.Route;
var BreadCrumbRoute = reactRouterDom.Route;
exports.Route = BreadCrumbRoute;
exports.createRoutesFromChildren = createRoutesFromChildren;
exports.default = useReactRouterBreadcrumbs;
exports["default"] = useReactRouterBreadcrumbs;
exports.getBreadcrumbs = getBreadcrumbs;
exports.humanize = humanize;
import React, { createElement } from 'react';
import { useLocation, Route, matchPath } from 'react-router';
import { useLocation, Route, matchPath } from 'react-router-dom';

@@ -310,3 +310,2 @@ var joinPaths = function joinPaths(paths) {

export default useReactRouterBreadcrumbs;
export { BreadCrumbRoute as Route, createRoutesFromChildren, getBreadcrumbs, humanize };
export { BreadCrumbRoute as Route, createRoutesFromChildren, useReactRouterBreadcrumbs as default, getBreadcrumbs, humanize };
import React from 'react';
import { useLocation, RouteObject, Params, PathPattern, PathRouteProps, LayoutRouteProps, IndexRouteProps } from 'react-router';
import { useLocation, RouteObject, Params, PathRouteProps, LayoutRouteProps, IndexRouteProps } from 'react-router-dom';
declare type Location = ReturnType<typeof useLocation>;
interface PathPattern<Path extends string = string> {
path: Path;
caseSensitive?: boolean;
end?: boolean;
}
export interface Options {

@@ -19,2 +24,3 @@ disableDefaults?: boolean;

location: Location;
[x: string]: unknown;
}

@@ -41,3 +47,3 @@ export declare type BreadcrumbComponentType<ParamKey extends string = string> = React.ComponentType<BreadcrumbComponentProps<ParamKey>>;

}) => BreadcrumbData[];
declare const useReactRouterBreadcrumbs: (routes?: BreadcrumbsRoute<string>[] | undefined, options?: Options | undefined) => BreadcrumbData[];
declare const useReactRouterBreadcrumbs: (routes?: BreadcrumbsRoute[], options?: Options) => BreadcrumbData[];
export default useReactRouterBreadcrumbs;

@@ -44,0 +50,0 @@ export declare function createRoutesFromChildren(children: React.ReactNode): BreadcrumbsRoute[];

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-router")):"function"==typeof define&&define.amd?define(["exports","react","react-router"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["react-router-breadcrumbs-hoc"]={},e.React,e.ReactRouter)}(this,(function(e,t,r){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(t),a=function(e){return e.join("/").replace(/\/\/+/g,"/")},c=/^:\w+$/,i=function(e){return"*"===e};function u(e,t){var r=e.split("/"),n=r.length;return r.some(i)&&(n+=-2),t&&(n+=2),r.filter((function(e){return!i(e)})).reduce((function(e,t){return c.test(t)?e+3:""===t?e+1:e+10}),n)}function s(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";return e.forEach((function(e,o){var c;if("string"!=typeof e.path&&!e.index&&!(null===(c=e.children)||void 0===c?void 0:c.length))throw new Error("useBreadcrumbs: `path` or `index` must be provided in every route object");if(e.path&&e.index)throw new Error("useBreadcrumbs: `path` and `index` cannot be provided at the same time");var i={relativePath:e.path||"",childrenIndex:o,route:e};if("/"===i.relativePath.charAt(0)){if(!i.relativePath.startsWith(n))throw new Error("useBreadcrumbs: The absolute path of the child route must start with the parent path");i.relativePath=i.relativePath.slice(n.length)}var l=a([n,i.relativePath]),h=r.concat(i);if(e.children&&e.children.length>0){if(e.index)throw new Error("useBreadcrumbs: Index route cannot have child routes");s(e.children,t,h,l)}t.push({path:l,score:u(l,e.index),routesMeta:h})})),t}var l=Symbol("NO_BREADCRUMB"),h=function(e){return e.replace(/^[\s_]+|[\s_]+$/g,"").replace(/[-_\s]+/g," ").replace(/^[a-z]/,(function(e){return e.toUpperCase()}))},d=function(e){var r=e.breadcrumb,n=e.match,a=e.location,c=e.props,i=Object.assign({match:n,location:a,key:n.pathname},c||{});return Object.assign(Object.assign({},i),{breadcrumb:"string"==typeof r?t.createElement("span",{key:i.key},r):o.default.createElement(r,Object.assign({},i))})},p=function(e){var t,n=e.currentSection,o=e.disableDefaults,a=e.excludePaths,c=e.defaultFormatter,i=e.location,u=e.pathSection,s=e.branches;return a&&a.some((function(e){return null!=r.matchPath({path:e,end:!0},u)}))?l:(s.some((function(e){var a=e.path,s=e.routesMeta,p=s[s.length-1].route,f=p.breadcrumb;if(!f&&p.index){var m=s[s.length-2];m&&m.route.breadcrumb&&(f=m.route.breadcrumb)}var b=p.caseSensitive,v=p.props,g=r.matchPath({path:a,end:!0,caseSensitive:b},u);return g&&null===f?(t=l,!0):!!g&&(!f&&o?(t=l,!0):(t=d({breadcrumb:f||(c?c(n):h(n)),match:Object.assign(Object.assign({},g),{route:p}),location:i,props:v}),!0))})),t||(o?l:function(e){var t=e.currentSection,n=e.location,o=e.pathSection,a=e.defaultFormatter,c=r.matchPath({end:!0,path:o},o);return d({breadcrumb:a?a(t):h(t),match:c,location:n})}({pathSection:u,currentSection:"/"===u?"Home":n,location:i,defaultFormatter:c})))},f=function(e){var t=e.routes,r=e.location,n=e.options,o=void 0===n?{}:n,a=r.pathname,c=function(e){return e.sort((function(e,t){return e.score!==t.score?t.score-e.score:function(e,t){return e.length===t.length&&e.slice(0,-1).every((function(e,r){return e===t[r]}))?e[e.length-1]-t[t.length-1]:0}(e.routesMeta.map((function(e){return e.childrenIndex})),t.routesMeta.map((function(e){return e.childrenIndex})))}))}(s(t)),i=[];return a.split("?")[0].split("/").reduce((function(e,t,n){var a=t?"".concat(e,"/").concat(t):"/";if("/"===a&&0!==n)return"";var u=p(Object.assign({currentSection:t,location:r,pathSection:a,branches:c},o));return u!==l&&i.push(u),"/"===a?"":a}),""),i};var m=r.Route;e.Route=m,e.createRoutesFromChildren=function e(t){var n=[];return o.default.Children.forEach(t,(function(t){if(o.default.isValidElement(t))if(t.type!==o.default.Fragment){!function(e,t){if(!e)throw new Error(t)}(t.type===r.Route,"[".concat("string"==typeof t.type?t.type:t.type.name,"] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>"));var a={caseSensitive:t.props.caseSensitive,element:t.props.element,index:t.props.index,path:t.props.path,breadcrumb:t.props.breadcrumb};t.props.children&&(a.children=e(t.props.children)),n.push(a)}else n.push.apply(n,e(t.props.children))})),n},e.default=function(e,t){return f({routes:e||[],location:r.useLocation(),options:t})},e.getBreadcrumbs=f,e.humanize=h,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-router-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["react-router-breadcrumbs-hoc"]={},e.React,e.ReactRouterDom)}(this,(function(e,t,r){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(t),a=function(e){return e.join("/").replace(/\/\/+/g,"/")},c=/^:\w+$/,i=function(e){return"*"===e};function u(e,t){var r=e.split("/"),n=r.length;return r.some(i)&&(n+=-2),t&&(n+=2),r.filter((function(e){return!i(e)})).reduce((function(e,t){return c.test(t)?e+3:""===t?e+1:e+10}),n)}function s(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";return e.forEach((function(e,o){var c;if("string"!=typeof e.path&&!e.index&&!(null===(c=e.children)||void 0===c?void 0:c.length))throw new Error("useBreadcrumbs: `path` or `index` must be provided in every route object");if(e.path&&e.index)throw new Error("useBreadcrumbs: `path` and `index` cannot be provided at the same time");var i={relativePath:e.path||"",childrenIndex:o,route:e};if("/"===i.relativePath.charAt(0)){if(!i.relativePath.startsWith(n))throw new Error("useBreadcrumbs: The absolute path of the child route must start with the parent path");i.relativePath=i.relativePath.slice(n.length)}var l=a([n,i.relativePath]),h=r.concat(i);if(e.children&&e.children.length>0){if(e.index)throw new Error("useBreadcrumbs: Index route cannot have child routes");s(e.children,t,h,l)}t.push({path:l,score:u(l,e.index),routesMeta:h})})),t}var l=Symbol("NO_BREADCRUMB"),h=function(e){return e.replace(/^[\s_]+|[\s_]+$/g,"").replace(/[-_\s]+/g," ").replace(/^[a-z]/,(function(e){return e.toUpperCase()}))},d=function(e){var r=e.breadcrumb,n=e.match,a=e.location,c=e.props,i=Object.assign({match:n,location:a,key:n.pathname},c||{});return Object.assign(Object.assign({},i),{breadcrumb:"string"==typeof r?t.createElement("span",{key:i.key},r):o.default.createElement(r,Object.assign({},i))})},p=function(e){var t,n=e.currentSection,o=e.disableDefaults,a=e.excludePaths,c=e.defaultFormatter,i=e.location,u=e.pathSection,s=e.branches;return a&&a.some((function(e){return null!=r.matchPath({path:e,end:!0},u)}))?l:(s.some((function(e){var a=e.path,s=e.routesMeta,p=s[s.length-1].route,f=p.breadcrumb;if(!f&&p.index){var m=s[s.length-2];m&&m.route.breadcrumb&&(f=m.route.breadcrumb)}var b=p.caseSensitive,v=p.props,g=r.matchPath({path:a,end:!0,caseSensitive:b},u);return g&&null===f?(t=l,!0):!!g&&(!f&&o?(t=l,!0):(t=d({breadcrumb:f||(c?c(n):h(n)),match:Object.assign(Object.assign({},g),{route:p}),location:i,props:v}),!0))})),t||(o?l:function(e){var t=e.currentSection,n=e.location,o=e.pathSection,a=e.defaultFormatter,c=r.matchPath({end:!0,path:o},o);return d({breadcrumb:a?a(t):h(t),match:c,location:n})}({pathSection:u,currentSection:"/"===u?"Home":n,location:i,defaultFormatter:c})))},f=function(e){var t=e.routes,r=e.location,n=e.options,o=void 0===n?{}:n,a=r.pathname,c=function(e){return e.sort((function(e,t){return e.score!==t.score?t.score-e.score:function(e,t){return e.length===t.length&&e.slice(0,-1).every((function(e,r){return e===t[r]}))?e[e.length-1]-t[t.length-1]:0}(e.routesMeta.map((function(e){return e.childrenIndex})),t.routesMeta.map((function(e){return e.childrenIndex})))}))}(s(t)),i=[];return a.split("?")[0].split("/").reduce((function(e,t,n){var a=t?"".concat(e,"/").concat(t):"/";if("/"===a&&0!==n)return"";var u=p(Object.assign({currentSection:t,location:r,pathSection:a,branches:c},o));return u!==l&&i.push(u),"/"===a?"":a}),""),i};var m=r.Route;e.Route=m,e.createRoutesFromChildren=function e(t){var n=[];return o.default.Children.forEach(t,(function(t){if(o.default.isValidElement(t))if(t.type!==o.default.Fragment){!function(e,t){if(!e)throw new Error(t)}(t.type===r.Route,"[".concat("string"==typeof t.type?t.type:t.type.name,"] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>"));var a={caseSensitive:t.props.caseSensitive,element:t.props.element,index:t.props.index,path:t.props.path,breadcrumb:t.props.breadcrumb};t.props.children&&(a.children=e(t.props.children)),n.push(a)}else n.push.apply(n,e(t.props.children))})),n},e.default=function(e,t){return f({routes:e||[],location:r.useLocation(),options:t})},e.getBreadcrumbs=f,e.humanize=h,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "use-react-router-breadcrumbs",
"version": "3.2.1",
"version": "4.0.0",
"description": "A hook for displaying and setting breadcrumbs for react router",

@@ -14,10 +14,11 @@ "main": "dist/cjs/index.js",

"react": ">=16.8",
"react-router": ">=6.0.0"
"react-router-dom": ">=6.0.0"
},
"scripts": {
"prepublishOnly": "yarn build && pinst --disable",
"build": "rollup -c && yarn types",
"build": "rollup -c && yarn type-declarations",
"test": "jest",
"test-build": "sh ./scripts/test-build.sh",
"types": "tsc -p tsconfig.json --declaration --emitDeclarationOnly",
"types": "tsc -p tsconfig.json --noEmit",
"type-declarations": "tsc -p tsconfig.json --declaration --emitDeclarationOnly --excludeFiles ./src/index.test.tsx",
"lint": "eslint ./src/**",

@@ -28,37 +29,37 @@ "postpublish": "pinst --enable",

"devDependencies": {
"@babel/cli": "^7.14.5",
"@babel/core": "^7.14.5",
"@babel/plugin-transform-runtime": "^7.14.5",
"@babel/preset-env": "^7.14.5",
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/react": "^17.0.11",
"@types/react-dom": "^17.0.7",
"@typescript-eslint/eslint-plugin": "^4.26.1",
"@typescript-eslint/parser": "^4.26.1",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.1",
"babel-eslint": "^10.1.0",
"enzyme": "^3.11.0",
"eslint": "^7.28.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "^6.0.0",
"jest": "^27.0.4",
"@babel/cli": "^7.18.10",
"@babel/core": "^7.19.0",
"@babel/plugin-transform-runtime": "^7.18.10",
"@babel/preset-env": "^7.19.0",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-typescript": "^8.5.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@types/react": "^18.0.18",
"@types/react-dom": "^18.0.6",
"@typescript-eslint/eslint-plugin": "^5.36.2",
"@typescript-eslint/parser": "^5.36.2",
"eslint": "^8.23.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-plugin-react": "^7.31.8",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.1",
"jest": "^29.0.2",
"jsdom": "^20.0.0",
"jsdom-global": "^3.0.2",
"pinst": "^2.1.6",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router": "^6.0.0",
"rollup": "^2.51.1",
"pinst": "^3.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0",
"rollup": "^2.79.0",
"rollup-plugin-size": "^0.2.2",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^4.3.2"
"typescript": "^4.8.3"
},

@@ -65,0 +66,0 @@ "keywords": [

@@ -108,3 +108,3 @@ <h3 align="center">

{ path: '/example', breadcrumb: 'Custom Example' },
{ path: '/custom-props, breadcrumb: CustomPropsBreadcrumb, props: { someProp: 'Hi' }},
{ path: '/custom-props', breadcrumb: CustomPropsBreadcrumb, props: { someProp: 'Hi' }},
];

@@ -111,0 +111,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc