compose-paths 1.1.3 → 1.2.2

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 CHANGED
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.2] - 2022-04-15
11
+
12
+ ### Removed / Fixed
13
+
14
+ - 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.
15
+
16
+ ## [1.2.1] - 2022-02-07
17
+
18
+ ### Fixed
19
+
20
+ - Broke ESM imports
21
+
22
+ ## [1.2.0] - 2022-02-06
23
+
24
+ ### Updated
25
+
26
+ - Basic index.d.ts, document aliases
27
+
10
28
  ## [1.1.3] - 2022-01-11
11
29
 
12
30
  ### Fixed
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # compose-paths
1
+ <h1 align="center"><code>compose-paths</code> 🛣</h1>
2
2
 
3
- <p>
3
+ <p align="center">
4
4
  <a href="https://github.com/shuckster/compose-paths/blob/master/LICENSE">
5
5
  <img
6
6
  alt="MIT license"
@@ -22,6 +22,8 @@
22
22
  $ pnpm i compose-paths
23
23
  ```
24
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
+
25
27
  ## Usage
26
28
 
27
29
  ### `Path` &rarr; `Alias`
@@ -47,6 +49,9 @@ paths.TEMPLATES
47
49
 
48
50
  paths.PUBLIC
49
51
  // "/dir/name/public"
52
+
53
+ paths.aliases
54
+ // ["TEMPLATES", "PAGES", "PUBLIC", "IMAGES"]
50
55
  ```
51
56
 
52
57
  ### `Path` &rarr; `Route` (via aliases)
@@ -105,8 +110,6 @@ pathFromRoute.aliases.forEach(route => {
105
110
 
106
111
  That's it!
107
112
 
108
- Behind the scenes `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.
109
-
110
113
  # Credits
111
114
 
112
115
  `compose-paths` was written by [Conan Theobald](https://github.com/shuckster/).
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * compose-paths
3
- * v1.1.3
3
+ * v1.2.2
4
4
  * https://github.com/shuckster/compose-paths
5
5
  * License: MIT
6
6
  */
@@ -0,0 +1,7 @@
1
+ /*
2
+ * compose-paths
3
+ * v1.2.2
4
+ * https://github.com/shuckster/compose-paths
5
+ * License: MIT
6
+ */
7
+ module.exports={composePaths:f,zip:h};const p=require("path").join,a="aliases";function f(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(p(...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)}
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * compose-paths
3
- * v1.1.3
3
+ * v1.2.2
4
4
  * https://github.com/shuckster/compose-paths
5
5
  * License: MIT
6
6
  */
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ type TComposedPaths = Array<string> & {
2
+ aliases: Array<string>
3
+ [key: string]: string
4
+ }
5
+
6
+ declare module 'compose-paths' {
7
+ /**
8
+ * @example
9
+ * const paths = composePaths(`
10
+ *
11
+ * ${__dirname}
12
+ * /src
13
+ * /html
14
+ * /templates = TEMPLATES
15
+ * /pages = PAGES
16
+ *
17
+ * /public = PUBLIC
18
+ * /images = IMAGES
19
+ *
20
+ * `)
21
+ *
22
+ * paths.TEMPLATES
23
+ * // "/dir/name/src/html/templates"
24
+ *
25
+ * paths.PUBLIC
26
+ * // "/dir/name/public"
27
+ *
28
+ * paths.aliases
29
+ * // ["TEMPLATES", "PAGES", "PUBLIC", "IMAGES"]
30
+ */
31
+ export function composePaths(pathChart: string | string[]): TComposedPaths
32
+ }
package/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import lib from './dist/compose-paths.esm.mjs'
1
+ import lib from './dist/esm/compose-paths.esm.js'
2
2
 
3
3
  const { composePaths, zip } = lib
4
4
 
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "compose-paths",
3
- "version": "1.1.3",
3
+ "browserGlobalName": "composePaths",
4
+ "version": "1.2.2",
4
5
  "description": "Define paths + routes without the repetition.",
5
6
  "author": "Conan Theobald",
6
7
  "license": "MIT",
@@ -11,16 +12,18 @@
11
12
  "routes",
12
13
  "concatenation"
13
14
  ],
15
+ "types": "index.d.ts",
14
16
  "main": "./dist/compose-paths.cjs.js",
15
17
  "module": "index.mjs",
16
18
  "exports": {
17
19
  "import": "./index.mjs",
18
- "require": "./dist/compose-paths.cjs.js",
19
- "browser": "./dist/compose-paths.browser.js",
20
- "default": "./dist/compose-paths.cjs.js"
20
+ "require": "./dist/cjs/compose-paths.cjs.js",
21
+ "default": "./dist/cjs/compose-paths.cjs.js"
21
22
  },
22
23
  "files": [
23
- "dist/*",
24
+ "dist/**/*.js",
25
+ "dist/**/package.json",
26
+ "index.d.ts",
24
27
  "index.mjs",
25
28
  "CHANGELOG.md",
26
29
  "README.md",
@@ -39,36 +42,24 @@
39
42
  "email": "bugs+compose-paths@conans.co.uk"
40
43
  },
41
44
  "devDependencies": {
42
- "@rollup/plugin-babel": "^5.3.0",
43
- "@rollup/plugin-commonjs": "^21.0.1",
44
- "@rollup/plugin-json": "^4.1.0",
45
- "@rollup/plugin-node-resolve": "^13.1.3",
46
- "@rollup/plugin-replace": "^3.0.1",
47
- "concurrently": "^7.0.0",
45
+ "concurrently": "^7.1.0",
48
46
  "cross-env": "^7.0.3",
49
- "esbuild": "^0.14.11",
50
- "eslint": "^8.6.0",
51
- "eslint-plugin-jest": "^25.3.4",
52
- "jest": "^27.4.7",
53
- "match-iz": "^1.11.1",
47
+ "esbuild": "^0.14.36",
48
+ "eslint": "^8.13.0",
49
+ "eslint-plugin-jest": "^26.1.4",
50
+ "jest": "^27.5.1",
51
+ "match-iz": "^3.3.1",
54
52
  "rimraf": "^3.0.2",
55
- "rollup": "^2.63.0",
56
- "rollup-plugin-cleanup": "^3.2.1",
57
- "rollup-plugin-node-builtins": "^2.1.2",
58
- "rollup-plugin-terser": "7.0.2",
59
- "typescript": "^4.5.4",
53
+ "typescript": "^4.6.3",
60
54
  "url-join": "^4.0.1"
61
55
  },
62
56
  "scripts": {
63
57
  "test": "jest",
64
58
  "lint": "pnpx eslint src/*.js tests/*.js",
65
59
  "build": "cross-env NODE_ENV=production pnpm run build:esbuild",
66
- "build:clean": "rimraf dist/; mkdir -p dist/",
60
+ "build:clean": "rimraf dist/; mkdir -p dist/{esm,cjs,browser}",
67
61
  "build:all": "pnpm run build:clean ; cross-env NODE_ENV=production pnpm run build",
68
- "build:rollup": "concurrently \"pnpm run build:rollup:node\" \"pnpm run build:rollup:not-node\"",
69
- "build:rollup:node": "rollup --config ./build-config/rollup.node.js",
70
- "build:rollup:not-node": "rollup --config ./build-config/rollup.not-node.js",
71
62
  "build:esbuild": "node ./build-config/esbuild.js"
72
63
  },
73
- "readme": "# compose-paths\n\n<p>\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## Usage\n\n### `Path` &rarr; `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```\n\n### `Path` &rarr; `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` &rarr; `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\nBehind the scenes `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# 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"
64
+ "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` &rarr; `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` &rarr; `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` &rarr; `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"
74
65
  }
@@ -1,7 +0,0 @@
1
- /*
2
- * compose-paths
3
- * v1.1.3
4
- * https://github.com/shuckster/compose-paths
5
- * License: MIT
6
- */
7
- module.exports={composePaths:p,zip:h};var f=require("path").join,a="aliases";function p(n){let 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){let{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),[])}var 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;let s=n[e];Object.defineProperty(n,t,{value:s,enumerable:!1})}}function _(n){let t=[],e=[],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)=>{let{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;let 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)}