compose-paths 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +6 -11
- package/dist/browser/compose-paths.browser.js +1 -1
- package/dist/cjs/compose-paths.cjs.js +2 -2
- package/dist/esm/compose-paths.esm.js +1 -1
- package/package.json +10 -12
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.3] - 2023-06-06
|
|
11
|
+
|
|
12
|
+
### Updated
|
|
13
|
+
|
|
14
|
+
- README tweaks
|
|
15
|
+
- Update build dependencies
|
|
16
|
+
|
|
17
|
+
## [1.2.2] - 2022-04-15
|
|
18
|
+
|
|
19
|
+
### Removed / Fixed
|
|
20
|
+
|
|
21
|
+
- Remove `browser` setting from `package.json`; seems to cause issues with CodeSandbox build process, and isn't really necessary since the browser-build is something that's interacted with manually.
|
|
22
|
+
|
|
10
23
|
## [1.2.1] - 2022-02-07
|
|
11
24
|
|
|
12
25
|
### Fixed
|
package/README.md
CHANGED
|
@@ -18,15 +18,7 @@
|
|
|
18
18
|
/></a>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
$ pnpm i compose-paths
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
`compose-paths` looks at the indentation-level of its input as the cue to concatenate lines together. Either `tabs` or `spaces` should be fine, so long as you're consistent.
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
|
|
29
|
-
### `Path` → `Alias`
|
|
21
|
+
Quickly throw together a few local paths and have them assigned to aliases or routes.
|
|
30
22
|
|
|
31
23
|
```js
|
|
32
24
|
const { composePaths } = require('compose-paths')
|
|
@@ -54,7 +46,11 @@ paths.aliases
|
|
|
54
46
|
// ["TEMPLATES", "PAGES", "PUBLIC", "IMAGES"]
|
|
55
47
|
```
|
|
56
48
|
|
|
57
|
-
|
|
49
|
+
`compose-paths` looks at the indentation-level of its input as the cue to concatenate lines together. Either `tabs` or `spaces` should be fine, so long as you're consistent.
|
|
50
|
+
|
|
51
|
+
## More examples
|
|
52
|
+
|
|
53
|
+
### `Path` → `Route` (via aliases and `zip`)
|
|
58
54
|
|
|
59
55
|
```js
|
|
60
56
|
const { composePaths, zip } = require('compose-paths')
|
|
@@ -76,7 +72,6 @@ const paths = composePaths(`
|
|
|
76
72
|
|
|
77
73
|
const staticRoutes = zip(routes, paths)
|
|
78
74
|
|
|
79
|
-
// Then, for example:
|
|
80
75
|
staticRoutes.forEach(([route, path]) => {
|
|
81
76
|
app.get(route, sendFile(path))
|
|
82
77
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* compose-paths
|
|
3
|
-
* v1.2.
|
|
3
|
+
* v1.2.3
|
|
4
4
|
* https://github.com/shuckster/compose-paths
|
|
5
5
|
* License: MIT
|
|
6
6
|
*/
|
|
7
|
-
module.exports={composePaths:
|
|
7
|
+
module.exports={composePaths:p,zip:h};const f=require("path").join,a="aliases";function p(n){const e=x(n).map(v),s=e.reduce(S,1/0),i=e.map(g(s)),o=b(i),r=_(o),c=o.map(u=>u==null?void 0:u.name).filter(Boolean),l=r;return o.forEach(j(l)),Object.defineProperty(l,a,{value:c,enumerable:!1})}function h(n,t,e){const{aliases:s=[],ignoreAliases:i=!1}=e||{};return(s.length&&!i?s:n[a]).reduce((r,c)=>(i&&s.includes(c)||r.push([n[c],t[c]]),r),[])}const m=/[\r\n]/,d=/(\s*\/\/[^\n\r]*)/,I=/^(\s*)([^$]*)/,A=/\s*=\s*([^$]+)/,P=/^\s*$/;function S(n,{indent:t}){return Math.min(n,t)}function g(n){return({indent:t,content:e})=>({indent:t-n,content:e})}function j(n){return({name:t,index:e})=>{if(!t)return n;const s=n[e];Object.defineProperty(n,t,{value:s,enumerable:!1})}}function _(n){const t=[],e=[];let s=-1,i=-1;return n.forEach(({indent:o,content:r})=>{if(i<=0)i=o;else if(o<=s){let c=1+(s-o)/i;for(;c--;)t.pop()}t.push(r),e.push(f(...t)),s=o}),e}function b(n){return n.map((t,e)=>{const{content:s,indent:i}=t,o=s.match(A);return o?{index:e,indent:i,content:s.slice(0,s.length-o[0].length),name:o[1]}:{index:e,indent:i,content:s}})}function v(n){var s;const t=[n,"",n],e=(s=n.match(I))!=null?s:t;return{indent:e[1].length,content:e[2]}}function x(n){return[n].flat().reduce((t,e)=>[...t,...e.split(m)],[]).filter(E).map(t=>t.replace(d,""))}function E(n){return!P.test(n)}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "compose-paths",
|
|
3
3
|
"browserGlobalName": "composePaths",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.3",
|
|
5
5
|
"description": "Define paths + routes without the repetition.",
|
|
6
6
|
"author": "Conan Theobald",
|
|
7
7
|
"license": "MIT",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
"import": "./index.mjs",
|
|
20
20
|
"require": "./dist/cjs/compose-paths.cjs.js",
|
|
21
|
-
"browser": "./dist/browser/compose-paths.browser.js",
|
|
22
21
|
"default": "./dist/cjs/compose-paths.cjs.js"
|
|
23
22
|
},
|
|
24
23
|
"files": [
|
|
@@ -43,15 +42,15 @@
|
|
|
43
42
|
"email": "bugs+compose-paths@conans.co.uk"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
|
-
"concurrently": "^
|
|
45
|
+
"concurrently": "^8.1.0",
|
|
47
46
|
"cross-env": "^7.0.3",
|
|
48
|
-
"esbuild": "^0.
|
|
49
|
-
"eslint": "^8.
|
|
50
|
-
"eslint-plugin-jest": "^
|
|
51
|
-
"jest": "^
|
|
52
|
-
"match-iz": "^
|
|
53
|
-
"rimraf": "^
|
|
54
|
-
"typescript": "^
|
|
47
|
+
"esbuild": "^0.17.19",
|
|
48
|
+
"eslint": "^8.42.0",
|
|
49
|
+
"eslint-plugin-jest": "^27.2.1",
|
|
50
|
+
"jest": "^29.5.0",
|
|
51
|
+
"match-iz": "^4.0.0",
|
|
52
|
+
"rimraf": "^5.0.1",
|
|
53
|
+
"typescript": "^5.1.3",
|
|
55
54
|
"url-join": "^4.0.1"
|
|
56
55
|
},
|
|
57
56
|
"scripts": {
|
|
@@ -61,6 +60,5 @@
|
|
|
61
60
|
"build:clean": "rimraf dist/; mkdir -p dist/{esm,cjs,browser}",
|
|
62
61
|
"build:all": "pnpm run build:clean ; cross-env NODE_ENV=production pnpm run build",
|
|
63
62
|
"build:esbuild": "node ./build-config/esbuild.js"
|
|
64
|
-
}
|
|
65
|
-
"readme": "<h1 align=\"center\"><code>compose-paths</code> 🛣</h1>\n\n<p align=\"center\">\n <a href=\"https://github.com/shuckster/compose-paths/blob/master/LICENSE\">\n <img\n alt=\"MIT license\"\n src=\"https://img.shields.io/npm/l/compose-paths?style=plastic\"\n /></a>\n <a href=\"https://bundlephobia.com/result?p=compose-paths\">\n <img\n alt=\"npm bundle size\"\n src=\"https://img.shields.io/bundlephobia/minzip/compose-paths?style=plastic\"\n /></a>\n <a href=\"https://www.npmjs.com/package/compose-paths\">\n <img\n alt=\"Version\"\n src=\"https://img.shields.io/npm/v/compose-paths?style=plastic\"\n /></a>\n</p>\n\n```sh\n$ pnpm i compose-paths\n```\n\n`compose-paths` looks at the indentation-level of its input as the cue to concatenate lines together. Either `tabs` or `spaces` should be fine, so long as you're consistent.\n\n## Usage\n\n### `Path` → `Alias`\n\n```js\nconst { composePaths } = require('compose-paths')\n\nconst paths = composePaths(`\n\n ${__dirname}\n /src\n /html\n /templates = TEMPLATES\n /pages = PAGES\n\n /public = PUBLIC\n /images = IMAGES\n\n`)\n\npaths.TEMPLATES\n// \"/dir/name/src/html/templates\"\n\npaths.PUBLIC\n// \"/dir/name/public\"\n\npaths.aliases\n// [\"TEMPLATES\", \"PAGES\", \"PUBLIC\", \"IMAGES\"]\n```\n\n### `Path` → `Route` (via aliases)\n\n```js\nconst { composePaths, zip } = require('compose-paths')\n\nconst routes = composePaths(`\n / = HOME\n /about = ABOUT\n /contact = CONTACT\n`)\n\nconst paths = composePaths(`\n ${__dirname}\n /src\n /html/pages\n /index.html = HOME\n /about.html = ABOUT\n /contact.html = CONTACT\n`)\n\nconst staticRoutes = zip(routes, paths)\n\n// Then, for example:\nstaticRoutes.forEach(([route, path]) => {\n app.get(route, sendFile(path))\n})\n```\n\n### `Path` → `Route` (directly)\n\n```js\nconst { composePaths } = require('compose-paths')\n\nconst pathFromRoute = composePaths(`\n\n ${__dirname}\n /src/html/pages\n /index.html = /\n /about.html = /about\n /contact.html = /contact\n\n`)\n\npathFromRoute['/']\n// \"/dir/name/src/html/pages/index.html\"\n\npathFromRoute['/contact']\n// \"/dir/name/src/html/pages/contact.html\"\n\npathFromRoute.aliases.forEach(route => {\n console.log(pathFromRoute[route])\n})\n```\n\nThat's it!\n\n# Credits\n\n`compose-paths` was written by [Conan Theobald](https://github.com/shuckster/).\n\nDid you find this useful? If so, I like [coffee ☕️](https://www.buymeacoffee.com/shuckster) :)\n\n## License\n\nMIT licensed: See [LICENSE](LICENSE)\n"
|
|
63
|
+
}
|
|
66
64
|
}
|