@future-scholars/paperlib-format-pubname-extension
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,1 +0,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; | ||
"use strict";var h=Object.defineProperty;var b=(i,t,e)=>t in i?h(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var c=(i,t)=>h(i,"name",{value:t,configurable:!0});var u=(i,t,e)=>(b(i,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=class d{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`)}}};c(d,"PLExtension");let m=d;const p=class p extends m{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}}});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,n,s){for(const o of e)if(n&&(o.publication=o.publication.replace(/\b\d{4}\b/g,"")),s)for(const a in s)o.publication.includes(a)&&(o.publication=s[a]);return e}async modifyPubnameHook(e,n,s){const o=PLExtAPI.extensionPreferenceService.get(this.id,"removeYear"),a=PLExtAPI.extensionPreferenceService.get(this.id,"customFormat");let r;if(a)try{r=JSON.parse(a)}catch(l){PLAPI.logService.error("Error parsing custom format",l,!0,"FormatPubnameExt")}return[this._modifyPubname(e,o,r),n,s]}async formatLibrary(){const e=await PLAPI.paperService.load("","addTime","desc"),n=PLExtAPI.extensionPreferenceService.get(this.id,"removeYear"),s=PLExtAPI.extensionPreferenceService.get(this.id,"customFormat");let o;if(s)try{o=JSON.parse(s)}catch(r){PLAPI.logService.error("Error parsing custom format",r,!0,"FormatPubnameExt")}const a=[];for(const r of e){const l=r.publication,[P]=this._modifyPubname([r],n,o);P.publication!==l&&a.push(P)}for(let r=0;r<a.length;r+=10)await PLAPI.paperService.update(a.slice(r,r+10),!1)}};c(p,"PaperlibFormatPubnameExtension");let f=p;async function y(){const i=new f;return await i.initialize(),i}c(y,"initialize");exports.initialize=y; |
{ | ||
"name": "@future-scholars/paperlib-format-pubname-extension", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "Paperlib", | ||
@@ -19,3 +19,3 @@ "description": "This extension helps you automatically format the publication name. For example: 2017 ABC Conference -> ABC Conference.", | ||
"@types/node": "16.18.1", | ||
"paperlib-api": "^0.1.1", | ||
"paperlib-api": "^0.1.2", | ||
"prettier": "^3.1.1", | ||
@@ -22,0 +22,0 @@ "prettier-plugin-organize-imports": "^3.2.4", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2
1
4336
13