@mapequation/infomap 1.8.0 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapequation/infomap",
3
- "version": "1.8.0",
3
+ "version": "2.0.2",
4
4
  "description": "Infomap network clustering algorithm",
5
5
  "browser": "index.js",
6
6
  "publishConfig": {
@@ -56,15 +56,15 @@
56
56
  "homepage": "https://www.mapequation.org/infomap",
57
57
  "devDependencies": {
58
58
  "arraybuffer-loader": "^1.0.8",
59
- "conventional-commits-parser": "^3.1.0",
60
- "git-raw-commits": "^2.0.7",
61
- "prettier": "^2.3.2",
62
- "raw-loader": "^4.0.1",
63
- "standard-version": "^8.0.2",
64
- "ts-loader": "^9.2.3",
65
- "typescript": "^4.3.4",
66
- "webpack": "^5.39.1",
67
- "webpack-cli": "^4.7.2"
59
+ "conventional-commits-parser": "^3.2.4",
60
+ "git-raw-commits": "^2.0.11",
61
+ "prettier": "^2.5.1",
62
+ "raw-loader": "^4.0.2",
63
+ "standard-version": "^9.3.2",
64
+ "ts-loader": "^9.2.6",
65
+ "typescript": "^4.5.4",
66
+ "webpack": "^5.66.0",
67
+ "webpack-cli": "^4.9.1"
68
68
  },
69
69
  "standard-version": {
70
70
  "bumpFiles": [
@@ -73,6 +73,10 @@
73
73
  {
74
74
  "filename": "src/io/version.cpp",
75
75
  "updater": "utils/update-version-cpp.js"
76
+ },
77
+ {
78
+ "filename": "CITATION.cff",
79
+ "updater": "utils/update-citation-cff.js"
76
80
  }
77
81
  ]
78
82
  },
package/parser.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { NodeBase, CluNode, TreeNode as JsonTreeNode } from "./filetypes";
2
2
  import type { Header as JsonHeader, Module } from "./index";
3
- declare type Header = Omit<JsonHeader, "directed">;
4
- declare type TreeNode = Omit<JsonTreeNode, "modules" | "modularCentrality">;
3
+ declare type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
4
+ declare type Header = Optional<JsonHeader, "directed">;
5
+ declare type TreeNode = Omit<JsonTreeNode, "modules" | "mec">;
5
6
  export declare type Result<NodeType extends NodeBase> = Header & {
6
7
  nodes: NodeType[];
7
8
  modules?: Module[];
@@ -9,7 +10,7 @@ export declare type Result<NodeType extends NodeBase> = Header & {
9
10
  export declare type Extension = "clu" | "tree";
10
11
  export declare function extension(filename: string): string | null;
11
12
  export declare function readFile(file: File): Promise<unknown>;
12
- export declare function parse(file: string | string[], type?: Extension): Result<CluNode<"moduleId">> | Result<TreeNode> | null;
13
+ export declare function parse(file: string | string[], type?: Extension, parseLinks?: boolean): Result<CluNode<"moduleId">> | Result<TreeNode> | null;
13
14
  export declare function parseClu<NodeType extends CluNode>(file: string | string[], nodeHeader?: string[]): Result<NodeType> | null;
14
15
  export declare function parseTree<NodeType extends TreeNode>(file: string | string[], nodeHeader?: string[], parseLinks?: boolean): Result<NodeType> | null;
15
16
  export declare function parseHeader(file: string | string[]): Header | null;
package/parser.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.infomap=e():t.infomap=e()}(self,(function(){return(()=>{"use strict";var t={};return(()=>{var e=t;Object.defineProperty(e,"__esModule",{value:!0}),e.parseHeader=e.parseTree=e.parseClu=e.parse=e.readFile=e.extension=void 0,e.extension=function(t){var e;return null!==(e=t.split(".").pop())&&void 0!==e?e:null},e.readFile=function(t){return new Promise(((e,n)=>{const i=new FileReader;i.onload=()=>e(i.result),i.onerror=n,i.readAsText(t)}))},e.parse=function(t,e){"string"==typeof t&&(t=t.split("\n"));const n=r(t);if(null===n)return null;if(e&&"clu"===e||n.includes("module")){if("node_id"===n[0])return i(t,n);if("state_id"===n[0])return i(t,n)}else if(e&&"tree"===e||n.includes("path")){if("name"===n[n.length-2])return o(t,n);if("state_id"===n[n.length-2])return o(t,n)}return null};const n={node_id:"id",module:"moduleId",flow:"flow",name:"name",state_id:"stateId",layer_id:"layerId",path:"path"};function i(t,e){var i;"string"==typeof t&&(t=t.split("\n"));const o=l(t);if(!o)return null;if(!e&&0===(e=null!==(i=r(t))&&void 0!==i?i:[]).length)return null;const u=[];for(const[i,o]of s(t)){const t=o.split(" ").map(Number);if(t.length<e.length)continue;const i={};for(let o=0;o<e.length;++o){const s=e[o];i[n[s]]=t[o]}u.push(i)}return Object.assign(Object.assign({},o),{nodes:u})}function o(t,e,i=!1){var o,u;"string"==typeof t&&(t=t.split("\n"));const a=l(t);if(!a)return null;if(!e&&0===(e=null!==(o=r(t))&&void 0!==o?o:[]).length)return null;const c=[];let d=0;for(const[i,o]of s(t)){d=i;const t=o.match(/[^\s"']+|"([^"]*)"/g);if(null===t||t.length<e.length)continue;const s={};for(let i=0;i<e.length;++i){const o=e[i],r=n[o];switch(o){case"path":s.path=t[i].split(":").map(Number);break;case"name":s.name=t[i].slice(1,-1);break;case"node_id":s.id=Number(t[i]);break;case"state_id":case"layer_id":case"flow":s[r]=Number(t[i])}}c.push(s)}if(++d,t.length<=d+1)return Object.assign(Object.assign({},a),{nodes:c});const f=[];let p=null;for(const[e,n]of function*(t,e=0){if(!(t.length<=e)&&t[e].startsWith("*Links"))for(let n=++e;n<t.length;++n){const e=t[n];0!==e.length&&(yield[n,e])}}(t,d)){if(n.startsWith("*Links")){const[t,...e]=n.split(" "),o="root"===t?[0]:t.split(":").map(Number),[s,r,l,u]=e.map(Number);p={path:o,enterFlow:s,exitFlow:r,numEdges:l,numChildren:u,links:i?[]:void 0},f.push(p);continue}if(!i||!p)continue;const[t,e,o]=n.split(" ").map(Number);null===(u=p.links)||void 0===u||u.push({source:t,target:e,flow:o})}return Object.assign(Object.assign({},a),{nodes:c,modules:f})}function*s(t){for(let e=0;e<t.length;++e){const n=t[e];if(!n.startsWith("#")&&0!==n.length){if(n.startsWith("*"))break;yield[e,n]}}}function r(t){const e=["# path","# node_id","# state_id"];"string"==typeof t&&(t=t.split("\n"));for(const n of t){if(!n.startsWith("#"))break;if(e.some((t=>n.startsWith(t))))return n.slice(2).split(" ")}return null}function l(t){var e,n,i,o,s,r,l;const u={};if("string"==typeof t&&(t=t.split("\n")),t.length<8)return null;const a=null===(e=t[0].match(/^# (v\d+\.\d+\.\d+)/))||void 0===e?void 0:e[1];if(!a)return null;u.version=a;const c=null===(n=t[1].match(/^# (.+)/))||void 0===n?void 0:n[1];if(!c)return null;u.args=c;for(let e=2;e<t.length;++e){const n=t[e];if(!n.startsWith("#"))break;const a=null===(i=n.match(/^# started at (.+)/))||void 0===i?void 0:i[1];if(a){u.startedAt=a;continue}const c=null===(o=n.match(/^# completed in (.+) s/))||void 0===o?void 0:o[1];if(c){u.completedIn=Number(c);continue}const d=n.match(/^# partitioned into (\d+) levels with (\d+) top modules/);if(d){u.numLevels=Number(d[1]),u.numTopModules=Number(d[2]);continue}const f=null===(s=n.match(/^# codelength (.+) bits/))||void 0===s?void 0:s[1];if(f){u.codelength=Number(f);continue}const p=null===(r=n.match(/^# relative codelength savings (.+)%/))||void 0===r?void 0:r[1];if(p){u.relativeCodelengthSavings=Number(p)/100;continue}const h=null===(l=n.match(/^# bipartite start id (\d+)/))||void 0===l?void 0:l[1];h&&(u.bipartiteStartId=Number(h))}return u}e.parseClu=i,e.parseTree=o,e.parseHeader=l})(),t})()}));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.infomap=t():e.infomap=t()}(self,(function(){return(()=>{"use strict";var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.parseHeader=t.parseTree=t.parseClu=t.parse=t.readFile=t.extension=void 0,t.extension=function(e){var t;return null!==(t=e.split(".").pop())&&void 0!==t?t:null},t.readFile=function(e){return new Promise(((t,n)=>{const o=new FileReader;o.onload=()=>t(o.result),o.onerror=n,o.readAsText(e)}))},t.parse=function(e,t,n=!1){"string"==typeof e&&(e=e.split("\n"));const s=r(e);if(null===s)return null;if(t&&"clu"===t||s.includes("module")){if("node_id"===s[0])return o(e,s);if("state_id"===s[0])return o(e,s)}else if(t&&"tree"===t||s.includes("path")){if("name"===s[s.length-2])return i(e,s,n);if("state_id"===s[s.length-2]||"layer_id"===s[s.length-1])return i(e,s,n)}return null};const n={node_id:"id",module:"moduleId",flow:"flow",name:"name",state_id:"stateId",layer_id:"layerId",path:"path"};function o(e,t){var o;"string"==typeof e&&(e=e.split("\n"));const i=l(e);if(!i)return console.warn("No header"),null;if(!t&&0===(t=null!==(o=r(e))&&void 0!==o?o:[]).length)return console.warn("No node header"),null;const a=[];for(const[o,i]of s(e)){const e=i.split(" ").map(Number);if(e.length<t.length)continue;const o={};for(let i=0;i<t.length;++i){const s=t[i];o[n[s]]=e[i]}a.push(o)}return Object.assign(Object.assign({},i),{nodes:a})}function i(e,t,o=!1){var i,a;"string"==typeof e&&(e=e.split("\n"));const u=l(e);if(!u)return console.warn("No header"),null;if(!t&&0===(t=null!==(i=r(e))&&void 0!==i?i:[]).length)return console.warn("No node header"),null;const c=[];let d=0;for(const[o,i]of s(e)){d=o;const e=i.match(/[^\s"']+|"([^"]*)"/g);if(null===e||e.length<t.length)continue;const s={};for(let o=0;o<t.length;++o){const i=t[o],r=n[i];switch(i){case"path":s.path=e[o].split(":").map(Number);break;case"name":s.name=e[o].slice(1,-1);break;case"node_id":s.id=Number(e[o]);break;case"state_id":case"layer_id":case"flow":s[r]=Number(e[o]);break;default:console.warn(`Unknown field ${i}`)}}c.push(s)}if(++d,e.length<=d+1)return Object.assign(Object.assign({},u),{nodes:c});const f=[];let p=null;const h=e[d];let m=!1;if(null==h?void 0:h.startsWith("*Links")){const e=h.trim().split(" ");m=e.length>1&&"directed"===e[1]}for(const[t,n]of function*(e,t=0){if(!(e.length<=t)&&e[t].startsWith("*Links"))for(let n=++t;n<e.length;++n){const t=e[n];0!==t.length&&(yield[n,t])}}(e,d)){if(n.startsWith("*Links")){const[e,t,...i]=n.split(" "),s="root"===t?[0]:t.split(":").map(Number),[r,l,a,u]=i.map(Number);p={path:s,enterFlow:r,exitFlow:l,numEdges:a,numChildren:u,links:o?[]:void 0},f.push(p);continue}if(!o||!p)continue;const[e,t,i]=n.split(" ").map(Number);null===(a=p.links)||void 0===a||a.push({source:e,target:t,flow:i})}return Object.assign(Object.assign({},u),{directed:m,nodes:c,modules:f})}function*s(e){for(let t=0;t<e.length;++t){const n=e[t];if(!n.startsWith("#")&&0!==n.length){if(n.startsWith("*"))break;yield[t,n]}}}function r(e){const t=["# path","# node_id","# state_id"];"string"==typeof e&&(e=e.split("\n"));for(const n of e){if(!n.startsWith("#"))break;if(t.some((e=>n.startsWith(e))))return n.slice(2).split(" ")}return null}function l(e){var t,n,o,i,s,r,l;const a={};if("string"==typeof e&&(e=e.split("\n")),e.length<8)return null;const u=null===(t=e[0].match(/^# (v\d+\.\d+\.\d+)/))||void 0===t?void 0:t[1];if(!u)return null;a.version=u;const c=null===(n=e[1].match(/^# (.+)/))||void 0===n?void 0:n[1];if(!c)return null;a.args=c;for(let t=2;t<e.length;++t){const n=e[t];if(!n.startsWith("#"))break;const u=null===(o=n.match(/^# started at (.+)/))||void 0===o?void 0:o[1];if(u){a.startedAt=u;continue}const c=null===(i=n.match(/^# completed in (.+) s/))||void 0===i?void 0:i[1];if(c){a.completedIn=Number(c);continue}const d=n.match(/^# partitioned into (\d+) levels with (\d+) top modules/);if(d){a.numLevels=Number(d[1]),a.numTopModules=Number(d[2]);continue}const f=null===(s=n.match(/^# codelength (.+) bits/))||void 0===s?void 0:s[1];if(f){a.codelength=Number(f);continue}const p=null===(r=n.match(/^# relative codelength savings (.+)%/))||void 0===r?void 0:r[1];if(p){a.relativeCodelengthSavings=Number(p)/100;continue}const h=null===(l=n.match(/^# bipartite start id (\d+)/))||void 0===l?void 0:l[1];h&&(a.bipartiteStartId=Number(h))}return a}t.parseClu=o,t.parseTree=i,t.parseHeader=l})(),e})()}));