@future-scholars/paperlib-format-pubname-extension 0.0.1
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/dist/main.js +1 -0
- package/package.json +32 -0
- package/readme.md +9 -0
package/dist/main.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var v=Object.defineProperty;var b=(r,t,e)=>t in r?v(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var p=(r,t)=>v(r,"name",{value:t,configurable:!0});var m=(r,t,e)=>(b(r,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("fs");require("path");const P=class P{constructor({id:t,defaultPreference:e}){m(this,"id");m(this,"defaultPreference");this.id=t,this.checkPreference(e),this.defaultPreference=e}checkPreference(t){if(typeof t!="object")throw new Error("Preference must be a dict");for(const e in t){if(!t[e].type||!["string","boolean","options","pathpicker"].includes(t[e].type))throw new Error(`Preference ${e} has wrong type ${t[e].type}`);if(!t[e].name)throw new Error(`Preference ${e} has no name`);if(!t[e].description)throw new Error(`Preference ${e} has no description`);if(t[e].value===void 0||t[e].value===null)throw new Error(`Preference ${e} has no default value`);if(t[e].type==="options"&&!t[e].options)throw new Error(`Preference ${e} has no options`)}}};p(P,"PLExtension");let f=P;const w=p(async(r,t,e,n=10)=>{let o=[];const a=[];let i;!r.hasOwnProperty("length")||!r.hasOwnProperty("slice")?i=Array.from(r):i=r;for(let s=0;s<i.length;s+=n){const c=i.slice(s,s+n),u=await Promise.allSettled(c.map(async l=>t.prototype===void 0?await t(l):await t.apply(void 0,l)));for(const[l,d]of u.entries())d.status==="rejected"?(a.push(d.reason),e?e.prototype===void 0?o.push(await e(c[l])):o.push(await e.apply(void 0,c[l])):o.push(null)):o.push(d.value)}return{results:o,errors:a}},"chunkRun"),y=class y extends f{constructor(){super({id:"@future-scholars/paperlib-format-pubname-extension",defaultPreference:{removeYear:{type:"boolean",name:"Remove year",description:"Remove year string from publication names",value:!0,order:0},customFormat:{type:"string",name:"Custom format",description:"A json string to define your custom format for publication names. If the publication name contains the key, it will be replaced by the value.",value:"",order:1}}});m(this,"disposeCallbacks");this.disposeCallbacks=[]}async initialize(){await PLExtAPI.extensionPreferenceService.register(this.id,this.defaultPreference),this.disposeCallbacks.push(PLAPI.hookService.hookModify("afterScrapeMetadata",this.id,"modifyPubnameHook")),this.disposeCallbacks.push(PLAPI.commandService.on("format_pubnames_event",e=>{this.formatLibrary()})),this.disposeCallbacks.push(PLAPI.commandService.registerExternel({id:"format_pubnames",description:"Format the publication names of your papers.",event:"format_pubnames_event"}))}async dispose(){PLExtAPI.extensionPreferenceService.unregister(this.id),this.disposeCallbacks.forEach(e=>e())}_modifyPubname(e,n,o){for(const a of e)if(n&&(a.publication=a.publication.replace(/\b\d{4}\b/g,"")),o)for(const i in o)a.publication.includes(i)&&(a.publication=o[i]);return e}async modifyPubnameHook(e,n,o){const a=PLExtAPI.extensionPreferenceService.get(this.id,"removeYear"),i=PLExtAPI.extensionPreferenceService.get(this.id,"customFormat");let s;if(i)try{s=JSON.parse(i)}catch(c){PLAPI.logService.error("Error parsing custom format",c,!0,"FormatPubnameExt")}return[this._modifyPubname(e,a,s),n,o]}async formatLibrary(){const e=await PLAPI.paperService.load("","addTime","desc"),n=PLExtAPI.extensionPreferenceService.get(this.id,"removeYear"),o=PLExtAPI.extensionPreferenceService.get(this.id,"customFormat");let a;if(o)try{a=JSON.parse(o)}catch(u){PLAPI.logService.error("Error parsing custom format",u,!0,"FormatPubnameExt")}const i=await w(e,async u=>await this._modifyPubname([u],n,a)),s=i.results.flat(),c=i.errors;for(const u of c)PLAPI.logService.error("Error formatting publication name",u,!0,"FormatPubnameExt");await PLAPI.paperService.update(s)}};p(y,"PaperlibFormatPubnameExtension");let h=y;async function g(){const r=new h;return await r.initialize(),r}p(g,"initialize");exports.initialize=g;
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@future-scholars/paperlib-format-pubname-extension",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"author": "Paperlib",
|
|
5
|
+
"description": "This extension helps you automatically format the publication name. For example: 2017 ABC Conference -> ABC Conference.",
|
|
6
|
+
"main": "dist/main.js",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"manifest_version": "1.0.0",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"prebuild": "tsc --noEmit",
|
|
11
|
+
"build": "tsc --noEmit && vite build"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=16.17.1"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
18
|
+
"@types/node": "16.18.1",
|
|
19
|
+
"paperlib-api": "^0.1.1",
|
|
20
|
+
"prettier": "^3.1.1",
|
|
21
|
+
"prettier-plugin-organize-imports": "^3.2.4",
|
|
22
|
+
"rollup-plugin-modify": "^3.0.0",
|
|
23
|
+
"typescript": "^5.1.3",
|
|
24
|
+
"vite": "^4.5.1"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"paperlib"
|
|
28
|
+
],
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
]
|
|
32
|
+
}
|