From 5aca285aef4db4ba0e98dedf69876365c6a8ef44 Mon Sep 17 00:00:00 2001 From: Dimitri Kopriwa Date: Wed, 27 Feb 2019 13:56:51 +0700 Subject: [PATCH] fix(dependencies): upgrade all dependencies --- docs/js/RoutesMap.md | 43 -------- docs/js/getPages.md | 60 ----------- docs/js/getRoutesMap.md | 82 --------------- docs/js/isPathParamsPath.md | 35 ------- docs/js/jsdoc.md | 186 +++++++++++++++++++++++++++++++++ docs/js/makeRoutes.md | 33 ------ docs/js/matchParamsPath.md | 30 ------ docs/motivation.md | 10 +- src/RoutesMap.js | 6 +- styleguide/jsdoc.sh | 6 +- styleguide/styleguide.ext.json | 31 ++---- 11 files changed, 202 insertions(+), 320 deletions(-) delete mode 100644 docs/js/RoutesMap.md delete mode 100644 docs/js/getPages.md delete mode 100644 docs/js/getRoutesMap.md delete mode 100644 docs/js/isPathParamsPath.md create mode 100644 docs/js/jsdoc.md delete mode 100644 docs/js/makeRoutes.md delete mode 100644 docs/js/matchParamsPath.md diff --git a/docs/js/RoutesMap.md b/docs/js/RoutesMap.md deleted file mode 100644 index fc6cfc0..0000000 --- a/docs/js/RoutesMap.md +++ /dev/null @@ -1,43 +0,0 @@ - - -## RoutesMap - -**Extends Map** - -RoutesMap class extend Map class and has an edited get method to retrieve route from parameterized path. - -Be aware that the `has` method will still check for the exact match. - -See: [https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map/get][1] - -```js -const { RoutesMap } = require('$PACKAGE_NAME'); -const routesMap = new RoutesMap([ - ['/', { name: 'Home' }], - ['/users/:id', { name: 'EditUser' }], -]); -// get as usual (See https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map/get) -const home = routesMap.get('/'); -// get as usual -const editUser = routesMap.get('/users/:id'); -// this should not work -const editUser = routesMap.get('/users/1'); -// now it work -
-  routesMap.get('/users/1'):
-
-  JSON.stringify(editUser, null, 2)
-
-``` - -### get - -The get method can get a routes that use params using a path with params set. - -#### Parameters - -- `key` It can get from the usual key or a routes with params such as `/users/1` - -Returns **V** The route configuration object of the route, or undefined if not found - -[1]: https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map/get diff --git a/docs/js/getPages.md b/docs/js/getPages.md deleted file mode 100644 index a0e8ae1..0000000 --- a/docs/js/getPages.md +++ /dev/null @@ -1,60 +0,0 @@ - - -## camelizePath - -This utility convert a path to a camelCase dotted string. -Every parameter within the path will see the colon replaced with a dollar - -### Parameters - -- `path` **[string][1]** A valid react router path - -### Examples - -```javascript -camelizePath('users/:id'); -// users.$id -camelizePath('/users/all'); -// users.all -``` - -Returns **[string][1]** camelizePath - a camel case dotted string representation of the path - -## getPages - -Utility to convert an array of routes configuration into a pages object. - -```javascript -const routesConfig = [{ path: '/', component: Dashboard, alias: 'dashboard' }, { path: '/users', component: UserList }]; -const pages = getPages(routesConfig); -// { dashboard: { path: '/' }, users: { path: '/users' } } -``` - -_Params_ - -`path` with params such as `/users/:id` will be added to `pages` with the colon replaced with the dollar sign. - -_Alias_: - -It is possible to duplicate a reference to a route called page alias. - -`{string|array} alias` that can be set in each `route`. - -Alias should not use dot (`.`) in their name unless you want to add at the root of the `pages` object, -in this case it will use it to traverse within the object to set the value. - -> The base path `/` can be added to `pages` only if an `alias` exist. - -### Parameters - -- `routesConfig` **([Array][2]<[Object][3]> | RoutesMap | [Map][4])** or routesMap - An array of routes configuration object or a routes map that will be translated into pages -- `pages` **[object][3]** A pages object (optional, default `{}`) -- `childKey` **[string][1]** When using a routes config, this will be the key used to find nested array of routes configuration object. (optional, default `routes`) - -[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String - -[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array - -[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object - -[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map diff --git a/docs/js/getRoutesMap.md b/docs/js/getRoutesMap.md deleted file mode 100644 index b4d5670..0000000 --- a/docs/js/getRoutesMap.md +++ /dev/null @@ -1,82 +0,0 @@ - - -## getRoutesMap - -This routeMap was created to store a map of all routes within applications. - -It set routes into a RoutesMap. This map one path to a route configuration. - -RoutesMap class extends from Map and has a modified get method that permit to get using `/users/1` and get `/users/:id` - -The path can be seen as the id of the route, and the configuration is what is actually used for the route. - -To set redirect route, just add from and to instead of path in the redirect route configuration - -Before adding a route to the map, it will test if the route exist and if it exist, it will merge the configuration. - -In non soft mode, it can throw error if the route already contain the component or is changing it's name within it's route configuration - -> We use core-js/es6/map and core-js/fn/symbol/for for old browsers that does not support Map, see [https://www.npmjs.com/package/core-js][1] for more information. - -### Parameters - -- `routesConfig` **[array][2]** A list of routes configuration object that will be flatten and set in the map -- `routesMap` **[RoutesMap][3]** An optional existing routeMap (optional, default `newRoutesMap()`) -- `options` **[object][4]** Options to configure getRoutesMap, - if options.soft is true, it will skip all errors found during the merge, - if options.soft is false, it will throw error if a route already:- have a component and a second is found - - have a name and different name is found (optional, default `{soft:false,childKey:'routes'}`) - -Returns **[RoutesMap][3]<[string][5], [object][4]>** The routeMap object used for your application - -## RoutesMap - -**Extends Map** - -RoutesMap class extend Map class and has an edited get method to retrieve route from parameterized path. - -Be aware that the `has` method will still check for the exact match. - -See: [https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map/get][6] - -```js -const { RoutesMap } = require('$PACKAGE_NAME'); -const routesMap = new RoutesMap([ - ['/', { name: 'Home' }], - ['/users/:id', { name: 'EditUser' }], -]); -// get as usual (See https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map/get) -const home = routesMap.get('/'); -// get as usual -const editUser = routesMap.get('/users/:id'); -// this should not work -const editUser = routesMap.get('/users/1'); -// now it work -
-  routesMap.get('/users/1'):
-
-  JSON.stringify(editUser, null, 2)
-
-``` - -### get - -The get method can get a routes that use params using a path with params set. - -#### Parameters - -- `key` It can get from the usual key or a routes with params such as `/users/1` - -Returns **V** The route configuration object of the route, or undefined if not found - -[1]: https://www.npmjs.com/package/core-js - -[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array - -[3]: #routesmap - -[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object - -[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String - -[6]: https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map/get diff --git a/docs/js/isPathParamsPath.md b/docs/js/isPathParamsPath.md deleted file mode 100644 index 5b5d99c..0000000 --- a/docs/js/isPathParamsPath.md +++ /dev/null @@ -1,35 +0,0 @@ - - -## matchParamsPath - -It will return true if the first path match the second path with params - -```js -const { matchParamsPath } = require('$PACKAGE_NAME/lib'); -
matchParamsPath('/users/1', '/users/:id'): {matchParamsPath('/users/1', '/users/:id').toString()}
; -``` - -### Parameters - -- `path` **[string][1]** The real path -- `pathWithParams` **[string][1]** The path with params - -### Examples - -```javascript -matchParamsPath('/users/1', '/users/:id'); -// true -matchParamsPath('/users', '/users/:id'); -// false -``` - -Returns **[boolean][2]** Return true if the compare match - -**Meta** - -- **deprecated**: This is deprecated. - - -[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String - -[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean diff --git a/docs/js/jsdoc.md b/docs/js/jsdoc.md new file mode 100644 index 0000000..201458f --- /dev/null +++ b/docs/js/jsdoc.md @@ -0,0 +1,186 @@ + + +## camelizePath + +This utility convert a path to a camelCase dotted string. +Every parameter within the path will see the colon replaced with a dollar + +### Parameters + +- `path` **[string][1]** A valid react router path + +### Examples + +```javascript +camelizePath('users/:id'); +// users.$id +camelizePath('/users/all'); +// users.all +``` + +Returns **[string][1]** camelizePath - a camel case dotted string representation of the path + +## getPages + +Utility to convert an array of routes configuration into a pages object. + +```javascript +const routesConfig = [{ path: '/', component: Dashboard, alias: 'dashboard' }, { path: '/users', component: UserList }]; +const pages = getPages(routesConfig); +// { dashboard: { path: '/' }, users: { path: '/users' } } +``` + +_Params_ + +`path` with params such as `/users/:id` will be added to `pages` with the colon replaced with the dollar sign. + +_Alias_: + +It is possible to duplicate a reference to a route called page alias. + +`{string|array} alias` that can be set in each `route`. + +Alias should not use dot (`.`) in their name unless you want to add at the root of the `pages` object, +in this case it will use it to traverse within the object to set the value. + +> The base path `/` can be added to `pages` only if an `alias` exist. + +### Parameters + +- `routesConfig` **([Array][2]<[Object][3]> | [RoutesMap][4] \| [Map][5])** or routesMap - An array of routes configuration object or a routes map that will be translated into pages +- `pages` **[object][3]** A pages object (optional, default `{}`) +- `childKey` **[string][1]** When using a routes config, this will be the key used to find nested array of routes configuration object. (optional, default `routes`) + +## getRoutesMap + +This routeMap was created to store a map of all routes within applications. + +It set routes into a RoutesMap. This map one path to a route configuration. + +RoutesMap class extends from Map and has a modified get method that permit to get using `/users/1` and get `/users/:id` + +The path can be seen as the id of the route, and the configuration is what is actually used for the route. + +To set redirect route, just add from and to instead of path in the redirect route configuration + +Before adding a route to the map, it will test if the route exist and if it exist, it will merge the configuration. + +In non soft mode, it can throw error if the route already contain the component or is changing it's name within it's route configuration + +> We use core-js/es6/map and core-js/fn/symbol/for for old browsers that does not support Map, see [https://www.npmjs.com/package/core-js][6] for more information. + +### Parameters + +- `routesConfig` **[array][2]** A list of routes configuration object that will be flatten and set in the map +- `routesMap` **[RoutesMap][4]** An optional existing routeMap (optional, default `newRoutesMap()`) +- `options` **[object][3]** Options to configure getRoutesMap, + if options.soft is true, it will skip all errors found during the merge, + if options.soft is false, it will throw error if a route already:- have a component and a second is found + - have a name and different name is found (optional, default `{soft:false,childKey:'routes'}`) + +Returns **[RoutesMap][4]<[string][1], [object][3]>** The routeMap object used for your application + +## makeRoutes + +This utility will check for routes configurations + +```js +const { makeRoutes } = require('$PACKAGE_NAME/lib'); +const Routes = makeRoutes([{ name: 'home', path: '/home', component: () =>
Home page
}]); +
{Routes[0].props.name} is home
; +``` + +### Parameters + +- `routesConfig` **([Array][2] \| [Map][5]<[string][1], [object][3]> | [RoutesMap][4]<[string][1], [object][3]>)** list of route configuration object, a map or a routes map +- `childKey` **[string][1]** the children key used for flattening pages (optional, default `routes`) + +### Examples + +```javascript +const routeList = makeRoutes([{ name: 'home', path: '/home', component: HomePage }]) +// return [] +``` + +Returns **[Array][2]** routeList - list of and + +## matchParamsPath + +It will return true if the first path match the second path with params + +```js +const { matchParamsPath } = require('$PACKAGE_NAME/lib'); +
matchParamsPath('/users/1', '/users/:id'): {matchParamsPath('/users/1', '/users/:id').toString()}
; +``` + +### Parameters + +- `path` **[string][1]** The real path +- `pathWithParams` **[string][1]** The path with params + +### Examples + +```javascript +matchParamsPath('/users/1', '/users/:id'); +// true +matchParamsPath('/users', '/users/:id'); +// false +``` + +Returns **[boolean][7]** Return true if the compare match + +## RoutesMap + +**Extends Map** + +RoutesMap class extend Map class and has an edited get method to retrieve route from parameterized path. + +Be aware that the `has` method will still check for the exact match. + +See: [https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map/get][8] + +```js +const { RoutesMap } = require('$PACKAGE_NAME'); +const routesMap = new RoutesMap([ + ['/', { name: 'Home' }], + ['/users/:id', { name: 'EditUser' }], +]); +// get as usual (See https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map/get) +const home = routesMap.get('/'); +// get as usual +const editUser = routesMap.get('/users/:id'); +// this is a valid path id +const editUserCc = routesMap.get('/users/1'); +// this is invalid path id but RoutesMap can get it +
+  routesMap.get('/users/1'):
+
+  JSON.stringify(editUser, null, 2)
+
+``` + +### get + +The get method can get a routes that use params using a path with params set. + +#### Parameters + +- `key` It can get from the usual key or a routes with params such as `/users/1` + +Returns **V** The route configuration object of the route, or undefined if not found + +[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String + +[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array + +[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object + +[4]: #routesmap + +[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map + +[6]: https://www.npmjs.com/package/core-js + +[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean + +[8]: https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Map/get diff --git a/docs/js/makeRoutes.md b/docs/js/makeRoutes.md deleted file mode 100644 index 05b6e1d..0000000 --- a/docs/js/makeRoutes.md +++ /dev/null @@ -1,33 +0,0 @@ - - -## makeRoutes - -This utility will check for routes configurations - -```js -const { makeRoutes } = require('$PACKAGE_NAME/lib'); -const Routes = makeRoutes([{ name: 'home', path: '/home', component: () =>
Home page
}]); -
{Routes[0].props.name} is home
; -``` - -### Parameters - -- `routesConfig` **([Array][1] \| [Map][2]<[string][3], [object][4]> | RoutesMap<[string][3], [object][4]>)** list of route configuration object, a map or a routes map -- `childKey` **[string][3]** the children key used for flattening pages (optional, default `routes`) - -### Examples - -```javascript -const routeList = makeRoutes([{ name: 'home', path: '/home', component: HomePage }]) -// return [] -``` - -Returns **[Array][1]** routeList - list of and - -[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array - -[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map - -[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String - -[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object diff --git a/docs/js/matchParamsPath.md b/docs/js/matchParamsPath.md deleted file mode 100644 index 776f7c9..0000000 --- a/docs/js/matchParamsPath.md +++ /dev/null @@ -1,30 +0,0 @@ - - -## matchParamsPath - -It will return true if the first path match the second path with params - -```js -const { matchParamsPath } = require('$PACKAGE_NAME/lib'); -
matchParamsPath('/users/1', '/users/:id'): {matchParamsPath('/users/1', '/users/:id').toString()}
; -``` - -### Parameters - -- `path` **[string][1]** The real path -- `pathWithParams` **[string][1]** The path with params - -### Examples - -```javascript -matchParamsPath('/users/1', '/users/:id'); -// true -matchParamsPath('/users', '/users/:id'); -// false -``` - -Returns **[boolean][2]** Return true if the compare match - -[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String - -[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean diff --git a/docs/motivation.md b/docs/motivation.md index ecd0f1a..c5437d4 100644 --- a/docs/motivation.md +++ b/docs/motivation.md @@ -21,13 +21,13 @@ Our utilities help to use this array of route configuration within our applicati A route configuration object is a configuration that can be use later to create the react-router `` or `` components. Read available props : -- ``: [doc](https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/Route.md). -- ``: [doc](https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/Redirect.md). +- ``: [Read documentation](https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/Route.md). +- ``: [Read documentation](https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/Redirect.md). -We use [getPages](#get-pages) utility to turn the `routeList` configuration into a `pages` object that can be traversed more efficiently than the array when writing links. +We use `getPages` utility to turn the `routeList` configuration into a `pages` object that can be traversed more efficiently than the array when writing links. ```js -const { getPages } = require('$PACKAGE_NAME/lib'); +const { getPages } = require('$PACKAGE_NAME'); // routes configuration const routes = [{ @@ -59,7 +59,7 @@ The flat architecture of the map and it's unique id makes it easier to found upd To creates a `routesMap`, just pass the array of route configuration to `getRoutesMap` function: ```js -const { getRoutesMap } = require('$PACKAGE_NAME/lib'); +const { getRoutesMap } = require('$PACKAGE_NAME'); // routes configuration const routes = [{ diff --git a/src/RoutesMap.js b/src/RoutesMap.js index 0961448..d08f44e 100644 --- a/src/RoutesMap.js +++ b/src/RoutesMap.js @@ -17,9 +17,9 @@ * const home = routesMap.get('/'); * // get as usual * const editUser = routesMap.get('/users/:id'); - * // this should not work - * const editUser = routesMap.get('/users/1'); - * // now it work + * // this is a valid path id + * const editUserCc = routesMap.get('/users/1'); + * // this is invalid path id but RoutesMap can get it *
  *   routesMap.get('/users/1'):
  *
diff --git a/styleguide/jsdoc.sh b/styleguide/jsdoc.sh
index ec5ed76..add3933 100755
--- a/styleguide/jsdoc.sh
+++ b/styleguide/jsdoc.sh
@@ -1,9 +1,5 @@
 #!/usr/bin/env bash
 set -e
 shopt -s extglob
-npm run jsdoc-documentation src/makeRoutes.js docs/js/makeRoutes.md
-npm run jsdoc-documentation src/getPages.js docs/js/getPages.md
-npm run jsdoc-documentation src/matchParamsPath.js docs/js/matchParamsPath.md
-npm run jsdoc-documentation src/getRoutesMap.js docs/js/getRoutesMap.md
-npm run jsdoc-documentation src/RoutesMap.js docs/js/RoutesMap.md
+npm run jsdoc-documentation 'src/**.js' docs/js/jsdoc.md
 
diff --git a/styleguide/styleguide.ext.json b/styleguide/styleguide.ext.json
index 81b0c93..1ad5c3f 100644
--- a/styleguide/styleguide.ext.json
+++ b/styleguide/styleguide.ext.json
@@ -4,7 +4,8 @@
     "**/*.test.{js,jsx,ts,tsx}",
     "**/*.spec.{js,jsx,ts,tsx}",
     "**/*.d.ts",
-    "**/src/index.js"
+    "**/src/index.js",
+    "**/src/RoutesMap.js"
   ],
   "sections": [
     {
@@ -29,32 +30,14 @@
         },
         {
           "name": "UI Component",
-          "components": "src/**/[A-Z]*.js"
+          "components": [
+            "src/**/[A-Z]*.js",
+            "src/**/[A-Z]*/index.js"
+          ]
         },
         {
           "name": "Utilities",
-          "sections": [
-            {
-              "name": "RoutesMap",
-              "content": "docs/js/RoutesMap.md"
-            },
-            {
-              "name": "getRoutesMap",
-              "content": "docs/js/getRoutesMap.md"
-            },
-            {
-              "name": "makeRoutes",
-              "content": "docs/js/makeRoutes.md"
-            },
-            {
-              "name": "getPages",
-              "content": "docs/js/getPages.md"
-            },
-            {
-              "name": "matchParamsPath",
-              "content": "docs/js/matchParamsPath.md"
-            }
-          ]
+          "content": "docs/js/jsdoc.md"
         }
       ]
     },