@future-scholars/paperlib-format-pubname-extension 0.0.2 → 0.0.4
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 -1
- package/package.json +2 -1
- package/readme.md +9 -6
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var b=Object.defineProperty;var y=(a,t,e)=>t in a?b(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var l=(a,t)=>b(a,"name",{value:t,configurable:!0});var u=(a,t,e)=>(y(a,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=class p{constructor({id:t,defaultPreference:e}){u(this,"id");u(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`)}}};l(p,"PLExtension");let f=p;const h=class h 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},customExactMatch:{type:"boolean",name:"Exact match",description:"If checked, the custom format will only be applied if the key is an exact match of the publication name.",value:!1,order:2}}});u(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,c,s,n=!1){for(const o of e)if(c&&(o.publication=o.publication.replace(/\s\d{4}\s/g," ").trim()),s)for(const i in s)n?o.publication===i&&(o.publication=s[i]):o.publication.toLowerCase().includes(i.toLowerCase())&&!o.publication.toLowerCase().includes("workshop")&&(o.publication=s[i]);return e}async modifyPubnameHook(e,c,s){const n=PLExtAPI.extensionPreferenceService.get(this.id,"removeYear"),o=PLExtAPI.extensionPreferenceService.get(this.id,"customFormat");let i;if(o)try{i=JSON.parse(o)}catch(m){PLAPI.logService.error("Error parsing custom format",m,!0,"FormatPubnameExt")}const r=PLExtAPI.extensionPreferenceService.get(this.id,"customExactMatch");return[this._modifyPubname(e,n,i,r),c,s]}async formatLibrary(){const e=await PLAPI.paperService.load("","addTime","desc"),c=PLExtAPI.extensionPreferenceService.get(this.id,"removeYear"),s=PLExtAPI.extensionPreferenceService.get(this.id,"customFormat");let n;if(s)try{n=JSON.parse(s)}catch(r){PLAPI.logService.error("Error parsing custom format",r,!0,"FormatPubnameExt")}const o=PLExtAPI.extensionPreferenceService.get(this.id,"customExactMatch"),i=[];for(const r of e){const m=r.publication,[P]=this._modifyPubname([r],c,n,o);P.publication!==m&&i.push(P)}for(let r=0;r<i.length;r+=10)await PLAPI.paperService.update(i.slice(r,r+10),!1)}};l(h,"PaperlibFormatPubnameExtension");let d=h;async function v(){const a=new d;return await a.initialize(),a}l(v,"initialize");exports.initialize=v;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@future-scholars/paperlib-format-pubname-extension",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"author": "Paperlib",
|
|
5
5
|
"description": "This extension helps you automatically format the publication name. For example: 2017 ABC Conference -> ABC Conference.",
|
|
6
|
+
"homepage": "https://github.com/Future-Scholars/paperlib-format-pubname-extension",
|
|
6
7
|
"main": "dist/main.js",
|
|
7
8
|
"type": "commonjs",
|
|
8
9
|
"manifest_version": "1.0.0",
|
package/readme.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
# Paperlib
|
|
1
|
+
# Paperlib Format Publication Name Extension
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This extension helps you automatically format the publication name when you import a paper into your library.
|
|
4
|
+
For example: 2017 ABC Conference -> ABC Conference.
|
|
5
|
+
It also supports define your custom formats.
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
`npm install`
|
|
7
|
+
For existing papers in your library, it provides a command `\format_pubnames`. Run it and boom!
|
|
7
8
|
|
|
8
|
-
##
|
|
9
|
-
|
|
9
|
+
## Custom Formats
|
|
10
|
+
```
|
|
11
|
+
{"some keywords": "target name", "another keywords": "another target name"}
|
|
12
|
+
```
|