New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@swan-io/chicane

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swan-io/chicane - npm Package Compare versions

Comparing version 1.2.5 to 1.3.0-rc.0

6

dist/concatRoutes.d.ts

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

import { RouteObject } from "./types";
import { ParsedRoute } from "./types";
export declare const addPrefixOnNonEmpty: (value: string, prefix: string) => string;
export declare const ensureSlashPrefix: (value: string) => string;
export declare const extractRoute: (route: string) => RouteObject;
export declare const concatRoutes: (routeA: RouteObject, routeB: RouteObject) => string;
export declare const parseRoute: (route: string) => ParsedRoute;
export declare const concatRoutes: (routeA: ParsedRoute, routeB: ParsedRoute) => string;

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

export declare const createGroup: <GroupName extends string, BaseRoute extends string, Routes extends Record<string, string>>(name: GroupName, baseRoute: BaseRoute, routes: Readonly<Routes>) => { [K in keyof Routes as K extends string ? `${GroupName}${K}` : never]: `${import("./types").ConcatPaths<import("./types").ExtractRoute<BaseRoute>["path"], import("./types").ExtractRoute<Routes[K]>["path"], import("./types").ExtractRoute<BaseRoute>["path"] extends infer T ? T extends import("./types").ExtractRoute<BaseRoute>["path"] ? T extends `/${string}` ? T : `/${T}` : never : never, import("./types").ExtractRoute<Routes[K]>["path"] extends infer T_1 ? T_1 extends import("./types").ExtractRoute<Routes[K]>["path"] ? T_1 extends `/${string}` ? T_1 : `/${T_1}` : never : never>}${import("./types").ConcatSearchs<import("./types").ExtractRoute<BaseRoute>["search"], import("./types").ExtractRoute<Routes[K]>["search"]> extends infer T_2 ? T_2 extends import("./types").ConcatSearchs<import("./types").ExtractRoute<BaseRoute>["search"], import("./types").ExtractRoute<Routes[K]>["search"]> ? T_2 extends "" ? T_2 : `?${T_2}` : never : never}${(import("./types").ExtractRoute<Routes[K]>["hash"] extends "" ? import("./types").ExtractRoute<BaseRoute>["hash"] : import("./types").ExtractRoute<Routes[K]>["hash"]) extends infer T_3 ? T_3 extends (import("./types").ExtractRoute<Routes[K]>["hash"] extends "" ? import("./types").ExtractRoute<BaseRoute>["hash"] : import("./types").ExtractRoute<Routes[K]>["hash"]) ? T_3 extends "" ? T_3 : `#${T_3}` : never : never}`; };
export declare const createGroup: <GroupName extends string, BaseRoute extends string, Routes extends Record<string, string>>(name: GroupName, baseRoute: BaseRoute, routes: Readonly<Routes>) => { [K in keyof Routes as K extends string ? `${GroupName}${K}` : never]: `${import("./types").ConcatPaths<import("./types").ParseRoute<BaseRoute>["path"], import("./types").ParseRoute<Routes[K]>["path"], import("./types").ParseRoute<BaseRoute>["path"] extends infer T ? T extends import("./types").ParseRoute<BaseRoute>["path"] ? T extends `/${string}` ? T : `/${T}` : never : never, import("./types").ParseRoute<Routes[K]>["path"] extends infer T_1 ? T_1 extends import("./types").ParseRoute<Routes[K]>["path"] ? T_1 extends `/${string}` ? T_1 : `/${T_1}` : never : never>}${import("./types").ConcatSearchs<import("./types").ParseRoute<BaseRoute>["search"], import("./types").ParseRoute<Routes[K]>["search"]> extends infer T_2 ? T_2 extends import("./types").ConcatSearchs<import("./types").ParseRoute<BaseRoute>["search"], import("./types").ParseRoute<Routes[K]>["search"]> ? T_2 extends "" ? T_2 : `?${T_2}` : never : never}${(import("./types").ParseRoute<Routes[K]>["hash"] extends "" ? import("./types").ParseRoute<BaseRoute>["hash"] : import("./types").ParseRoute<Routes[K]>["hash"]) extends infer T_3 ? T_3 extends (import("./types").ParseRoute<Routes[K]>["hash"] extends "" ? import("./types").ParseRoute<BaseRoute>["hash"] : import("./types").ParseRoute<Routes[K]>["hash"]) ? T_3 extends "" ? T_3 : `#${T_3}` : never : never}`; };

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

import { ExtractRoutesParams, GetAreaRoutes, ParamsArg, PrependBasePath, Simplify } from "./types";
import { GetAreaRoutes, GetRoutesParams, ParamsArg, ParseRoutes, PrependBasePath, Simplify } from "./types";
export declare const createRouter: <Routes extends Record<string, string>, BasePath extends string = string>(routes: Readonly<Routes>, options?: {
basePath?: BasePath;
}) => {
useRoute: <RouteName extends keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>> | Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>>>>(routeNames: readonly RouteName[]) => RouteName extends string ? {
useRoute: <RouteName extends keyof GetAreaRoutes<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>> | Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>>>>(routeNames: readonly RouteName[]) => RouteName extends string ? {
key: string;
name: RouteName;
params: Simplify<(ExtractRoutesParams<GetAreaRoutes<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>>> & ExtractRoutesParams<Omit<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>>>>)[RouteName]>;
params: Simplify<(GetRoutesParams<GetAreaRoutes<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>>> & GetRoutesParams<Omit<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>, keyof GetAreaRoutes<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>>>>)[RouteName]>;
} | undefined : never;
push: <RouteName_1 extends Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>>>>(routeName: RouteName_1, ...args: ParamsArg<ExtractRoutesParams<Omit<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>>>>[RouteName_1]>) => void;
replace: <RouteName_2 extends Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>>>>(routeName: RouteName_2, ...args: ParamsArg<ExtractRoutesParams<Omit<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>>>>[RouteName_2]>) => void;
} & (Omit<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>>> extends infer T ? { [RouteName_3 in keyof T]: (...args: ParamsArg<ExtractRoutesParams<Omit<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, import("./types").ExtractRoute<BasePath>>>>>[RouteName_3]>) => string; } : never);
push: <RouteName_1 extends Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>>>>(routeName: RouteName_1, ...args: ParamsArg<GetRoutesParams<Omit<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>, keyof GetAreaRoutes<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>>>>[RouteName_1]>) => void;
replace: <RouteName_2 extends Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>>>>(routeName: RouteName_2, ...args: ParamsArg<GetRoutesParams<Omit<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>, keyof GetAreaRoutes<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>>>>[RouteName_2]>) => void;
} & (Omit<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>, keyof GetAreaRoutes<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>>> extends infer T ? { [RouteName_3 in keyof T]: (...args: ParamsArg<GetRoutesParams<Omit<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>, keyof GetAreaRoutes<PrependBasePath<BasePath, ParseRoutes<Routes>, import("./types").ParseRoute<BasePath>["path"]>>>>[RouteName_3]>) => string; } : never);

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

var e=require("history"),r=require("react"),t=require("use-sync-external-store/shim/with-selector"),n=require("use-sync-external-store/shim"),a=require("@emotion/hash");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var u=/*#__PURE__*/i(r),c=/*#__PURE__*/o(a),s=function(e,r){return""===e?e:r+e},l=function(e){return"/"===e[0]?e:"/"+e},h=function(r){var t=e.parsePath(r),n=t.pathname,a=t.search,o=t.hash,i=void 0===o?"":o;return{path:void 0===n?"":n,search:(void 0===a?"":a).substring(1),hash:i.substring(1)}},f=function(e,r){var t=l(e.path),n=l(r.path),a="/"===t?n:"/"===n?t:t+n,o=""===e.search?r.search:e.search+s(r.search,"&"),i=""===r.hash?e.hash:r.hash;return a+s(o,"?")+s(i,"#")};function p(){return p=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},p.apply(this,arguments)}function v(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function d(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return v(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?v(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}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 y=function(e){return e[0]},m=function(e){return e},g=function(e){return""!==e},b=function(e){return e.startsWith(":")},w=function(e,r){return e.length===r.length&&e.every(function(e,t){return e===r[t]})},S=function(e,r){return(null==e?void 0:e.key)===(null==r?void 0:r.key)},k=function(e){for(var r,t={},n=d(new URLSearchParams(e));!(r=n()).done;){var a=r.value,o=a[0],i=a[1],u=t[o];t[o]=null!=u?"string"==typeof u?[u,i]:u.concat(i):i}return t},O=function(e,r,t){var n=e+(""!==e?"&":"")+encodeURIComponent(r);return""!==t?n+"="+encodeURIComponent(t):n},P=function(e){var r=Object.keys(e);if(0===r.length)return"";var t="";r.sort();for(var n=0,a=r;n<a.length;n++){var o=a[n],i=e[o];if(null!=i)if("string"==typeof i)t=O(t,o,i);else for(var u,c=d(i);!(u=c()).done;)t=O(t,o,u.value)}return""===t?"":"?"+t},x=function(e,r){var t=e.search,n=e.hash,a=e.pathname.substring(1),o=""!==a?r?a.split("/").filter(g).map(decodeURIComponent):a.split("/").map(decodeURIComponent):[],i=""!==t?k(t):{},u=""!==n?decodeURIComponent(n.substring(1)):null,s="/"+o.map(encodeURIComponent).join("/"),l=P(i),h=null!=u?"#"+encodeURIComponent(u):"",f=s+l+h;return p({key:c.default(s)+"-"+c.default(l+h),path:o,search:i},null!==u&&{hash:u},{raw:{path:s,search:l,hash:h},toString:function(){return f}})},C=new Set,j="undefined"!=typeof window&&window.document&&window.document.createElement?e.createBrowserHistory():e.createMemoryHistory(),R=x(j.location,!0),U=!1;R.toString()!==e.createPath(j.location)&&j.replace(R.toString()),j.listen(function(e){var r=x(e.location,!1);if(r.toString()!==R.toString()){U=!0;var t=r.raw.search!==R.raw.search,n=t?{}:R.search;if(t)for(var a in r.search)if(Object.prototype.hasOwnProperty.call(r.search,a)){var o=r.search[a];if(null==o)continue;var i=R.search[a];n[a]=null!=i&&"string"!=typeof i&&"string"!=typeof o&&w(o,i)?i:o}R=p({key:r.key,path:r.raw.path!==R.raw.path?r.path:R.path,search:n},null!=r.hash&&{hash:r.hash},{raw:r.raw,toString:r.toString}),C.forEach(function(e){return e(R)})}});var I=function(e){return C.add(e),function(){C.delete(e)}},A=function(){return R},E=u.createContext(A),N=E.Provider,L=function(){return u.useContext(E)},q=function(r){var t=e.parsePath(r),n=t.pathname,a=t.search,o=t.hash;j.push({pathname:void 0===n?"":n,search:void 0===a?"":a,hash:void 0===o?"":o})},T=function(r){var t=e.parsePath(r),n=t.pathname,a=t.search,o=t.hash;j.replace({pathname:void 0===n?"":n,search:void 0===a?"":a,hash:void 0===o?"":o})},M=function(e){for(var r,t=e.split("/").filter(g),n=[],a=t.length>0?4*t.length:5,o=d(t);!(r=o()).done;){var i=r.value,u=b(i);a+=u?2:3,n.push(u?{name:i.substring(1)}:encodeURIComponent(i))}return{ranking:a,path:n}},W=function(r,t){if(t.endsWith("/*")){var n=e.parsePath(t.slice(0,-2)).pathname,a=M(void 0===n?"/":n);return{isArea:!0,name:r,ranking:a.ranking-1,path:a.path,search:{},hash:void 0}}for(var o,i=e.parsePath(t),u=i.pathname,c=i.search,s=void 0===c?"":c,l=i.hash,h=void 0===l?"":l,f=M(void 0===u?"/":u),p=f.ranking,v=f.path,y={},m=d(new URLSearchParams(s.substring(1)));!(o=m()).done;){var g=o.value[0];(w=g).startsWith(":")&&w.endsWith("[]")?y[g.substring(1,g.length-2)]="multiple":b(g)&&(y[g.substring(1,g.length)]="unique")}return{isArea:!1,name:r,ranking:p,path:v,search:y,hash:b(h.substring(1))?h.substring(2):void 0};var w},K=function(e,r){var t=e.path,n=r.isArea,a=r.path;if(!(!n&&t.length!==a.length||n&&t.length<a.length)){for(var o={},i=0;i<a.length;i++){var u=t[i],c=a[i];if(null!=c)if("string"==typeof c){if(c!==u)return}else{if(null==u)return;o[c.name]=u}}if(n)return o;for(var s in r.search)if(Object.prototype.hasOwnProperty.call(r.search,s)){var l=r.search[s],h=e.search[s];if(null==l||null==h)continue;if("multiple"===l){o[s]="string"==typeof h?[h]:h;continue}"string"==typeof h?o[s]=h:null!=h[0]&&(o[s]=h[0])}return null!=r.hash&&null!=e.hash&&(o[r.hash]=e.hash),o}},_=function(e,r){void 0===r&&(r={});var t="/"+e.path.map(function(e){return encodeURIComponent("string"==typeof e?e:String(r[e.name]))}).join("/"),n="",a="";if(null!=e.search){var o={};for(var i in r){var u=r[i];Object.prototype.hasOwnProperty.call(r,i)&&Object.prototype.hasOwnProperty.call(e.search,i)&&null!=u&&(o[i]=u)}n=P(o)}if(null!=e.hash){var c=r[e.hash];"string"==typeof c&&(a="#"+encodeURIComponent(c))}return{pathname:t,search:n,hash:a}},B=function(r){var t=r.href,a=r.replace,o=void 0!==a&&a,i=r.target,c=u.useMemo(function(){return e.parsePath(t).pathname},[t]),s=L(),l=function(){return c===s().raw.path},h=n.useSyncExternalStore(I,l,l),f=o||h,p=null==i||"_self"===i;return{active:h,onClick:u.useCallback(function(e){e.defaultPrevented||!p||0!==e.button||e.metaKey||e.altKey||e.ctrlKey||e.shiftKey||(e.preventDefault(),f?T(t):q(t))},[f,p,t])}},D=["onClick","className","replace","style","target","to","activeClassName","activeStyle"],H=u.forwardRef(function(e,r){var t=e.onClick,n=e.className,a=e.replace,o=e.style,i=e.target,c=e.to,s=e.activeClassName,l=e.activeStyle,h=function(e,r){if(null==e)return{};var t,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r.indexOf(t=o[n])>=0||(a[t]=e[t]);return a}(e,D),f=B({href:c,replace:a,target:i}),v=f.active,d=f.onClick;return u.createElement("a",p({},h,{ref:r,href:c,onClick:function(e){null==t||t(e),d(e)},target:i,className:v&&null!=s?null==n?s:n+" "+s:n,style:v&&null!=l?null==o?l:p({},o,l):o}))});H.displayName="Link";var F={A:!0,INPUT:!0,SELECT:!0,TEXTAREA:!0};exports.Link=H,exports.ServerUrlProvider=function(r){var t=r.children,n=e.parsePath(r.value),a=n.pathname,o=n.search,i=n.hash,c=x({pathname:void 0===a?"/":a,search:void 0===o?"":o,hash:void 0===i?"":i},!1);return u.createElement(N,{children:t,value:function(){return c}})},exports.createGroup=function(e,r,t){var n=h(r),a={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(a[e+o]=f(n,h(t[o])));return a},exports.createRouter=function(r,n){void 0===n&&(n={});var a=n.basePath,o=void 0===a?"":a,i={path:h(o).path,search:"",hash:""},c={},s=[];for(var l in r)if(Object.prototype.hasOwnProperty.call(r,l)){var v=W(l,""!==o?f(i,h(r[l])):r[l]);c[l]=v,s.push(v)}s.sort(function(e,r){return r.ranking-e.ranking});for(var g={},b=0;b<s.length;b++){var w=s[b];null==w||w.isArea||function(){var r=w.name;g[r]=function(t){return e.createPath(_(c[r],t))}}()}return p({useRoute:function(e){var r=u.useMemo(function(){return s.filter(function(r){return e.includes(r.name)})},[JSON.stringify(e)]),n=L(),a=function(){return function(e,r){for(var t,n=d(r);!(t=n()).done;){var a=t.value,o=K(e,a);if(null!=o)return{key:e.key,name:a.name,params:o}}}(n(),r)};return t.useSyncExternalStoreWithSelector(I,a,a,m,S)},push:function(e){return j.push(_(c[e],y([].slice.call(arguments,1))))},replace:function(e){return j.replace(_(c[e],y([].slice.call(arguments,1))))}},g)},exports.decodeSearch=k,exports.encodeSearch=P,exports.getLocation=A,exports.pushUnsafe=q,exports.replaceUnsafe=T,exports.subscribeToLocation=I,exports.useFocusReset=function(e){var r=e.route,t=e.containerRef,n=null==r?void 0:r.key.split("-")[0];u.useEffect(function(){var e=t.current;if(e&&U)try{null!=e.getAttribute("tabIndex")||F[e.nodeName]||e.setAttribute("tabIndex","-1"),e.focus()}catch(e){}},[t,n])},exports.useLinkProps=B,exports.useLocation=function(){var e=L();return n.useSyncExternalStore(I,e,e)},exports.useNavigationBlocker=function(e,r){u.useEffect(function(){if(e){var t=j.block(function(e){window.confirm(r)&&(t(),e.retry())});return t}},[e])};
var e=require("history"),t=require("react"),r=require("use-sync-external-store/shim/with-selector"),n=require("use-sync-external-store/shim"),a=require("@emotion/hash");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var u=/*#__PURE__*/i(t),c=/*#__PURE__*/o(a),s=function(e,t){return""===e?e:t+e},l=function(e){return"/"===e[0]?e:"/"+e},h=function(t){var r=e.parsePath(t),n=r.pathname,a=r.search,o=r.hash,i=void 0===o?"":o;return{path:void 0===n?"":n,search:(void 0===a?"":a).substring(1),hash:i.substring(1)}},f=function(e,t){var r=l(e.path),n=l(t.path),a="/"===r?n:"/"===n?r:r+n,o=""===e.search?t.search:e.search+s(t.search,"&"),i=""===t.hash?e.hash:t.hash;return a+s(o,"?")+s(i,"#")};function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},p.apply(this,arguments)}function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function d(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return v(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}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 y=function(e){return e[0]},m=function(e){return e},g=function(e){return""!==e},b=function(e){return e.startsWith(":")},w=function(e,t){return e.length===t.length&&e.every(function(e,r){return e===t[r]})},S=function(e,t){return(null==e?void 0:e.key)===(null==t?void 0:t.key)},k=function(e){for(var t,r={},n=d(new URLSearchParams(e));!(t=n()).done;){var a=t.value,o=a[0],i=a[1],u=r[o];r[o]=null!=u?"string"==typeof u?[u,i]:u.concat(i):i}return r},O=function(e,t,r){var n=e+(""!==e?"&":"")+encodeURIComponent(t);return""!==r?n+"="+encodeURIComponent(r):n},x=function(e){var t=Object.keys(e);if(0===t.length)return"";var r="";t.sort();for(var n=0,a=t;n<a.length;n++){var o=a[n],i=e[o];if(null!=i)if("string"==typeof i)r=O(r,o,i);else for(var u,c=d(i);!(u=c()).done;)r=O(r,o,u.value)}return""===r?"":"?"+r},P=function(e,t){var r=e.search,n=e.hash,a=e.pathname.substring(1),o=""!==a?t?a.split("/").filter(g).map(decodeURIComponent):a.split("/").map(decodeURIComponent):[],i=""!==r?k(r):{},u=""!==n?decodeURIComponent(n.substring(1)):null,s="/"+o.map(encodeURIComponent).join("/"),l=x(i),h=null!=u?"#"+encodeURIComponent(u):"",f=s+l+h;return p({key:c.default(s)+"-"+c.default(l+h),path:o,search:i},null!==u&&{hash:u},{raw:{path:s,search:l,hash:h},toString:function(){return f}})},C=new Set,j="undefined"!=typeof window&&window.document&&window.document.createElement?e.createBrowserHistory():e.createMemoryHistory(),R=P(j.location,!0),U=!1;R.toString()!==e.createPath(j.location)&&j.replace(R.toString()),j.listen(function(e){var t=P(e.location,!1);if(t.toString()!==R.toString()){U=!0;var r=t.raw.search!==R.raw.search,n=r?{}:R.search;if(r)for(var a in t.search)if(Object.prototype.hasOwnProperty.call(t.search,a)){var o=t.search[a];if(null==o)continue;var i=R.search[a];n[a]=null!=i&&"string"!=typeof i&&"string"!=typeof o&&w(o,i)?i:o}R=p({key:t.key,path:t.raw.path!==R.raw.path?t.path:R.path,search:n},null!=t.hash&&{hash:t.hash},{raw:t.raw,toString:t.toString}),C.forEach(function(e){return e(R)})}});var I=function(e){return C.add(e),function(){C.delete(e)}},E=function(){return R},A=u.createContext(E),N=A.Provider,L=function(){return u.useContext(A)},q=function(t){var r=e.parsePath(t),n=r.pathname,a=r.search,o=r.hash;j.push({pathname:void 0===n?"":n,search:void 0===a?"":a,hash:void 0===o?"":o})},T=function(t){var r=e.parsePath(t),n=r.pathname,a=r.search,o=r.hash;j.replace({pathname:void 0===n?"":n,search:void 0===a?"":a,hash:void 0===o?"":o})},M=function(t,r){var n,a=e.parsePath(r),o=a.pathname,i=void 0===o?"/":o,u=a.search,c=a.hash,s=i.endsWith("/*"),l=function(e){for(var t,r=e.split("/").filter(g),n=[],a=r.length>0?4*r.length:5,o=d(r);!(t=o()).done;){var i=t.value,u=b(i);a+=u?2:3,n.push(u?{name:i.substring(1)}:encodeURIComponent(i))}return{ranking:a,path:n}}(s?i.slice(0,-2):i),h=l.ranking,f=l.path,p={};if(null!=u)for(var v,y=d(new URLSearchParams(u.substring(1)));!(v=y()).done;){var m=v.value[0];(n=m).startsWith(":")&&n.endsWith("[]")?p[m.substring(1,m.length-2)]="multiple":b(m)&&(p[m.substring(1,m.length)]="unique")}return{isArea:s,name:t,ranking:s?h-1:h,path:f,search:p,hash:null!=c&&b(c.substring(1))?c.substring(2):void 0}},W=function(e,t){var r=e.path,n=t.isArea,a=t.path;if(!(!n&&r.length!==a.length||n&&r.length<a.length)){for(var o={},i=0;i<a.length;i++){var u=r[i],c=a[i];if(null!=c)if("string"==typeof c){if(c!==u)return}else{if(null==u)return;o[c.name]=u}}for(var s in t.search)if(Object.prototype.hasOwnProperty.call(t.search,s)){var l=t.search[s],h=e.search[s];if(null==l||null==h)continue;if("multiple"===l){o[s]="string"==typeof h?[h]:h;continue}"string"==typeof h?o[s]=h:null!=h[0]&&(o[s]=h[0])}return null!=t.hash&&null!=e.hash&&(o[t.hash]=e.hash),o}},K=function(e,t){void 0===t&&(t={});var r="/"+e.path.map(function(e){return encodeURIComponent("string"==typeof e?e:String(t[e.name]))}).join("/"),n="",a="";if(null!=e.search){var o={};for(var i in t){var u=t[i];Object.prototype.hasOwnProperty.call(t,i)&&Object.prototype.hasOwnProperty.call(e.search,i)&&null!=u&&(o[i]=u)}n=x(o)}if(null!=e.hash){var c=t[e.hash];"string"==typeof c&&(a="#"+encodeURIComponent(c))}return{pathname:r,search:n,hash:a}},_=function(t){var r=t.href,a=t.replace,o=void 0!==a&&a,i=t.target,c=u.useMemo(function(){return e.parsePath(r).pathname},[r]),s=L(),l=function(){return c===s().raw.path},h=n.useSyncExternalStore(I,l,l),f=o||h,p=null==i||"_self"===i;return{active:h,onClick:u.useCallback(function(e){e.defaultPrevented||!p||0!==e.button||e.metaKey||e.altKey||e.ctrlKey||e.shiftKey||(e.preventDefault(),f?T(r):q(r))},[f,p,r])}},B=["onClick","className","replace","style","target","to","activeClassName","activeStyle"],D=u.forwardRef(function(e,t){var r=e.onClick,n=e.className,a=e.replace,o=e.style,i=e.target,c=e.to,s=e.activeClassName,l=e.activeStyle,h=function(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(a[r]=e[r]);return a}(e,B),f=_({href:c,replace:a,target:i}),v=f.active,d=f.onClick;return u.createElement("a",p({},h,{ref:t,href:c,onClick:function(e){null==r||r(e),d(e)},target:i,className:v&&null!=s?null==n?s:n+" "+s:n,style:v&&null!=l?null==o?l:p({},o,l):o}))});D.displayName="Link";var H={A:!0,INPUT:!0,SELECT:!0,TEXTAREA:!0};exports.Link=D,exports.ServerUrlProvider=function(t){var r=t.children,n=e.parsePath(t.value),a=n.pathname,o=n.search,i=n.hash,c=P({pathname:void 0===a?"/":a,search:void 0===o?"":o,hash:void 0===i?"":i},!1);return u.createElement(N,{children:r,value:function(){return c}})},exports.createGroup=function(e,t,r){var n=h(t),a={};for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(a[e+o]=f(n,h(r[o])));return a},exports.createRouter=function(t,n){void 0===n&&(n={});var a=n.basePath,o=void 0===a?"":a,i={path:h(o).path,search:"",hash:""},c={},s=[];for(var l in t)if(Object.prototype.hasOwnProperty.call(t,l)){var v=M(l,""!==o?f(i,h(t[l])):t[l]);c[l]=v,s.push(v)}s.sort(function(e,t){return t.ranking-e.ranking});for(var g={},b=0;b<s.length;b++){var w=s[b];null==w||w.isArea||function(){var t=w.name;g[t]=function(r){return e.createPath(K(c[t],r))}}()}return p({useRoute:function(e){var t=u.useMemo(function(){return s.filter(function(t){return e.includes(t.name)})},[JSON.stringify(e)]),n=L(),a=function(){return function(e,t){for(var r,n=d(t);!(r=n()).done;){var a=r.value,o=W(e,a);if(null!=o)return{key:e.key,name:a.name,params:o}}}(n(),t)};return r.useSyncExternalStoreWithSelector(I,a,a,m,S)},push:function(e){return j.push(K(c[e],y([].slice.call(arguments,1))))},replace:function(e){return j.replace(K(c[e],y([].slice.call(arguments,1))))}},g)},exports.decodeSearch=k,exports.encodeSearch=x,exports.getLocation=E,exports.pushUnsafe=q,exports.replaceUnsafe=T,exports.subscribeToLocation=I,exports.useFocusReset=function(e){var t=e.route,r=e.containerRef,n=null==t?void 0:t.key.split("-")[0];u.useEffect(function(){var e=r.current;if(e&&U)try{null!=e.getAttribute("tabIndex")||H[e.nodeName]||e.setAttribute("tabIndex","-1"),e.focus()}catch(e){}},[r,n])},exports.useLinkProps=_,exports.useLocation=function(){var e=L();return n.useSyncExternalStore(I,e,e)},exports.useNavigationBlocker=function(e,t){u.useEffect(function(){if(e){var r=j.block(function(e){window.confirm(t)&&(r(),e.retry())});return r}},[e])};
//# sourceMappingURL=index.js.map

@@ -14,3 +14,3 @@ export declare type Search = Record<string, string | string[]>;

};
export declare type RouteObject = Readonly<{
export declare type ParsedRoute = Readonly<{
path: string;

@@ -20,7 +20,2 @@ search: string;

}>;
export declare type RawLocation = Readonly<{
path: string;
search: string;
hash: string;
}>;
export declare type Location = Readonly<{

@@ -31,18 +26,22 @@ key: string;

hash?: string;
raw: RawLocation;
raw: Readonly<{
path: string;
search: string;
hash: string;
}>;
toString(): string;
}>;
export declare type SplitAndFilterEmpty<Value extends string, Separator extends string> = Value extends `${infer Head}${Separator}${infer Tail}` ? Head extends "" ? SplitAndFilterEmpty<Tail, Separator> : [Head, ...SplitAndFilterEmpty<Tail, Separator>] : Value extends "" ? [] : [Value];
export declare type ExtractPathParams<Path extends string, Parts = SplitAndFilterEmpty<Path, "/">> = Parts extends [infer Head, ...infer Tail] ? Head extends `:${infer Name}` ? {
export declare type GetPathParams<Path extends string, Parts = SplitAndFilterEmpty<Path, "/">> = Parts extends [infer Head, ...infer Tail] ? Head extends `:${infer Name}` ? {
[K in Name]: string;
} & ExtractPathParams<Path, Tail> : ExtractPathParams<Path, Tail> : {};
export declare type ExtractSearchParams<Search extends string, Parts = SplitAndFilterEmpty<Search, "&">> = Parts extends [infer Head, ...infer Tail] ? Head extends `:${infer Name}[]` ? {
} & GetPathParams<Path, Tail> : GetPathParams<Path, Tail> : {};
export declare type GetSearchParams<Search extends string, Parts = SplitAndFilterEmpty<Search, "&">> = Parts extends [infer Head, ...infer Tail] ? Head extends `:${infer Name}[]` ? {
[K in Name]?: string[] | undefined;
} & ExtractSearchParams<Search, Tail> : Head extends `:${infer Name}` ? {
} & GetSearchParams<Search, Tail> : Head extends `:${infer Name}` ? {
[K in Name]?: string | undefined;
} & ExtractSearchParams<Search, Tail> : ExtractSearchParams<Search, Tail> : {};
export declare type ExtractHashParams<Value extends string> = Value extends `:${infer Name}` ? {
} & GetSearchParams<Search, Tail> : GetSearchParams<Search, Tail> : {};
export declare type GetHashParams<Value extends string> = Value extends `:${infer Name}` ? {
[K in Name]?: string | undefined;
} : {};
export declare type ExtractRoute<Route extends string> = Route extends `${infer Path}?${infer Search}#${infer Hash}` ? {
export declare type ParseRoute<Route extends string> = Route extends `${infer Path}?${infer Search}#${infer Hash}` ? {
path: Path;

@@ -64,3 +63,5 @@ search: Search;

};
declare type ExtractRouteParams<Route extends string, ExtractedRoute extends RouteObject = ExtractRoute<Route>> = ExtractPathParams<ExtractedRoute["path"]> & ExtractSearchParams<ExtractedRoute["search"]> & ExtractHashParams<ExtractedRoute["hash"]>;
export declare type ParseRoutes<Routes extends Record<string, string>> = {
[K in keyof Routes]: ParseRoute<Routes[K]>;
};
declare type AddPrefixOnNonEmpty<Value extends string, Prefix extends string> = Value extends "" ? Value : `${Prefix}${Value}`;

@@ -70,17 +71,25 @@ declare type EnsureSlashPrefix<Value extends string> = Value extends `/${string}` ? Value : `/${Value}`;

export declare type ConcatSearchs<SearchA extends string, SearchB extends string> = SearchA extends "" ? SearchB : `${SearchA}${AddPrefixOnNonEmpty<SearchB, "&">}`;
declare type StringifyRouteObject<Route extends RouteObject> = `${Route["path"]}${AddPrefixOnNonEmpty<Route["search"], "?">}${AddPrefixOnNonEmpty<Route["hash"], "#">}`;
export declare type ConcatRoutes<RouteA extends string, RouteB extends string, ExtractedRouteA extends RouteObject = ExtractRoute<RouteA>, ExtractedRouteB extends RouteObject = ExtractRoute<RouteB>> = StringifyRouteObject<{
path: ConcatPaths<ExtractedRouteA["path"], ExtractedRouteB["path"]>;
search: ConcatSearchs<ExtractedRouteA["search"], ExtractedRouteB["search"]>;
hash: ExtractedRouteB["hash"] extends "" ? ExtractedRouteA["hash"] : ExtractedRouteB["hash"];
}>;
export declare type PrependBasePath<BasePath extends string, Routes extends Record<string, string>, ExtractedBase extends RouteObject = ExtractRoute<BasePath>> = {
[K in keyof Routes]: ConcatRoutes<ExtractedBase["path"], Routes[K]>;
export declare type ConcatParsedRoutes<RouteA extends ParsedRoute, RouteB extends ParsedRoute> = {
path: ConcatPaths<RouteA["path"], RouteB["path"]>;
search: ConcatSearchs<RouteA["search"], RouteB["search"]>;
hash: RouteB["hash"] extends "" ? RouteA["hash"] : RouteB["hash"];
};
export declare type GetAreaRoutes<Routes extends Record<string, string>> = {
[K in keyof Routes as Routes[K] extends `${string}/*` ? K : never]: Routes[K] extends `${infer Rest}/*` ? Rest : never;
export declare type ConcatRoutes<RouteA extends string, RouteB extends string, Route extends ParsedRoute = ConcatParsedRoutes<ParseRoute<RouteA>, ParseRoute<RouteB>>> = `${Route["path"]}${AddPrefixOnNonEmpty<Route["search"], "?">}${AddPrefixOnNonEmpty<Route["hash"], "#">}`;
export declare type PrependBasePath<BasePath extends string, Routes extends Record<string, ParsedRoute>, CleanBasePath extends string = ParseRoute<BasePath>["path"]> = {
[K in keyof Routes]: {
path: ConcatPaths<Routes[K]["path"], CleanBasePath>;
search: Routes[K]["search"];
hash: Routes[K]["hash"];
};
};
export declare type ExtractRoutesParams<Routes extends Record<string, string>> = {
[K in keyof Routes]: ExtractRouteParams<Routes[K]>;
export declare type GetAreaRoutes<Routes extends Record<string, ParsedRoute>> = {
[K in keyof Routes as Routes[K]["path"] extends `${string}/*` ? K : never]: Routes[K]["path"] extends `${infer Rest}/*` ? {
path: Rest;
search: Routes[K]["search"];
hash: Routes[K]["hash"];
} : never;
};
export declare type GetRoutesParams<Routes extends Record<string, ParsedRoute>> = {
[K in keyof Routes]: GetPathParams<Routes[K]["path"]> & GetSearchParams<Routes[K]["search"]> & GetHashParams<Routes[K]["hash"]>;
};
declare type EmptyRecord = Record<string | number | symbol, never>;

@@ -87,0 +96,0 @@ export declare type Simplify<T> = T extends EmptyRecord ? {} : {

{
"name": "@swan-io/chicane",
"version": "1.2.5",
"version": "1.3.0-rc.0",
"license": "MIT",

@@ -57,15 +57,15 @@ "description": "A simple and safe router for React and TypeScript",

"@testing-library/react": "^12.1.5",
"@types/react": "^17.0.47",
"@types/react": "^17.0.50",
"@types/react-dom": "^17.0.17",
"@types/use-sync-external-store": "^0.0.3",
"jsdom": "^20.0.0",
"microbundle": "^0.15.0",
"microbundle": "^0.15.1",
"prettier": "^2.7.1",
"prettier-plugin-organize-imports": "^3.1.0",
"prettier-plugin-organize-imports": "^3.1.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"tsd": "^0.22.0",
"typescript": "^4.7.4",
"vitest": "^0.22.1"
"tsd": "^0.24.1",
"typescript": "^4.8.3",
"vitest": "^0.23.4"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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