@mapequation/infomap 1.9.0 → 2.1.0

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.9.0",
3
+ "version": "2.1.0",
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,11 @@
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 Path = {
6
+ path: string | number[];
7
+ };
8
+ declare type TreeNode = Omit<JsonTreeNode, "modules" | "mec" | "path"> & Path;
5
9
  export declare type Result<NodeType extends NodeBase> = Header & {
6
10
  nodes: NodeType[];
7
11
  modules?: Module[];
@@ -9,8 +13,8 @@ export declare type Result<NodeType extends NodeBase> = Header & {
9
13
  export declare type Extension = "clu" | "tree";
10
14
  export declare function extension(filename: string): string | null;
11
15
  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 parseClu<NodeType extends CluNode>(file: string | string[], nodeHeader?: string[]): Result<NodeType> | null;
14
- export declare function parseTree<NodeType extends TreeNode>(file: string | string[], nodeHeader?: string[], parseLinks?: boolean): Result<NodeType> | null;
15
- export declare function parseHeader(file: string | string[]): Header | null;
16
+ export declare function parse(file: string | string[], type?: Extension, parseLinks?: boolean): Result<CluNode<"moduleId">> | Result<TreeNode> | null;
17
+ export declare function parseClu<NodeType extends CluNode>(file: string | string[], nodeHeader?: string[]): Result<NodeType>;
18
+ export declare function parseTree<NodeType extends TreeNode>(file: string | string[], nodeHeader?: string[], parseLinks?: boolean): Result<NodeType>;
19
+ export declare function parseHeader(file: string | string[]): Header;
16
20
  export {};
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 r=s(e);if(t&&"clu"===t||r.includes("module")){if("node_id"===r[0])return o(e,r);if("state_id"===r[0])return o(e,r)}else if(t&&"tree"===t||r.includes("path")){if("name"===r[r.length-2])return i(e,r,n);if("state_id"===r[r.length-2]||"layer_id"===r[r.length-1])return i(e,r,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){"string"==typeof e&&(e=e.split("\n"));const o=l(e);t||(t=s(e));const i=[];for(const[o,s]of r(e)){const e=s.split(" ").map(Number);if(e.length<t.length)continue;const r={};for(let o=0;o<t.length;++o){const i=t[o];r[n[i]]=e[o]}if(void 0===r.id||void 0===r.moduleId||void 0===r.flow)throw new Error(`Invalid node at line ${o+1}: ${s}`);i.push(r)}return Object.assign(Object.assign({},o),{nodes:i})}function i(e,t,o=!1){var i;"string"==typeof e&&(e=e.split("\n"));const a=l(e);t||(t=s(e));const d=[];let c=0;for(const[o,i]of r(e)){c=o;const e=i.match(/[^\s"']+|"([^"]*)"/g);if(null===e||e.length<t.length)continue;const r={};for(let o=0;o<t.length;++o){const i=t[o],s=n[i];switch(i){case"path":r.path=e[o];break;case"name":r.name=e[o].slice(1,-1);break;case"node_id":r.id=Number(e[o]);break;case"state_id":case"layer_id":case"flow":r[s]=Number(e[o]);break;default:console.warn(`Unknown field ${i}`)}}if(void 0===r.path||void 0===r.flow||void 0===r.name||void 0===r.id)throw new Error(`Invalid node at line ${o+1}: ${i}`);d.push(r)}if(++c,e.length<=c+1)return Object.assign(Object.assign({},a),{nodes:d});const u=[];let f=null;const p=e[c];let h=!1;if(null==p?void 0:p.startsWith("*Links")){const e=p.trim().split(" ");h=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,c)){if(n.startsWith("*Links")){const[e,t,...i]=n.split(" "),r="root"===t?[0]:t.split(":").map(Number),[s,l,a,d]=i.map(Number);f={path:r,enterFlow:s,exitFlow:l,numEdges:a,numChildren:d,links:o?[]:void 0},u.push(f);continue}if(!o||!f)continue;const[e,t,r]=n.split(" ").map(Number);null===(i=f.links)||void 0===i||i.push({source:e,target:t,flow:r})}return Object.assign(Object.assign({},a),{directed:h,nodes:d,modules:u})}function*r(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 s(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(" ")}throw new Error("Could not parse node header")}function l(e){var t,n,o,i,r,s,l;const a={};if("string"==typeof e&&(e=e.split("\n")),e.length<8)throw new Error("Expected file header to have at least 8 lines");const d=null===(t=e[0].match(/^# (v\d+\.\d+\.\d+)/))||void 0===t?void 0:t[1];if(!d)throw new Error("Could not parse version");a.version=d;const c=null===(n=e[1].match(/^# (.+)/))||void 0===n?void 0:n[1];if(!c)throw new Error("Could not parse args");a.args=c;for(let t=2;t<e.length;++t){const n=e[t];if(!n.startsWith("#"))break;const d=null===(o=n.match(/^# started at (.+)/))||void 0===o?void 0:o[1];if(d){a.startedAt=d;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 u=n.match(/^# partitioned into (\d+) levels with (\d+) top modules/);if(u){a.numLevels=Number(u[1]),a.numTopModules=Number(u[2]);continue}const f=null===(r=n.match(/^# codelength (.+) bits/))||void 0===r?void 0:r[1];if(f){a.codelength=Number(f);continue}const p=null===(s=n.match(/^# relative codelength savings (.+)%/))||void 0===s?void 0:s[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))}if(!(a.startedAt&&a.completedIn&&a.numLevels&&a.numTopModules&&a.codelength&&a.relativeCodelengthSavings))throw new Error("Could not parse file header");return a}t.parseClu=o,t.parseTree=i,t.parseHeader=l})(),e})()}));