{"version":3,"file":"token-saver.cjs","sources":["../src/token-saver.js"],"sourcesContent":["/**\n * TokenSaver – remove polite fluff to save tokens.\n */\nclass TokenSaver {\n    static DEFAULT_CONFIG = {\n      removePoliteness: true,\n      removeFillers: true,\n      removeRedundantIntros: true,\n      tokenCharRatio: 4 // chars per token estimate\n    };\n  \n    // Combined patterns. Each match also eats any trailing punctuation + spaces.\n    static PATTERNS = {\n      politeness:\n        /\\b(?:please|kindly)\\b[,.!?]?\\s*|\\b(?:thank(?:\\s*you)?|thanks)\\b[,.!?]?\\s*|\\b(?:if you don['’]t mind|if you could|if possible)\\b[,.!?]?\\s*|\\bappreciate\\s*(?:it|your help)\\b[,.!?]?\\s*/gi,\n      fillers:\n        /\\b(?:um|uh|er|hmm|like|you know|actually|basically|literally|so|well|anyway|anyhow)\\b[,.!?]?\\s*/gi,\n      redundantIntros:\n        /^(?:i (?:was (?:wondering|hoping|thinking) if you (?:could|would|can)|(?:am|'m) (?:trying|looking|hoping) to)|can you|could you|would you be able to|(?:i'd|i would) like you to|i want you to|i need you to|i'm looking for|i'm trying to find|could i get|can i get)\\s+/i\n    };\n  \n    constructor(options = {}) {\n      this.config = { ...TokenSaver.DEFAULT_CONFIG, ...options };\n    }\n  \n    clean(prompt = '') {\n      let txt = `${prompt}`;\n  \n      if (this.config.removePoliteness) txt = txt.replace(TokenSaver.PATTERNS.politeness, ' ');\n      if (this.config.removeFillers) txt = txt.replace(TokenSaver.PATTERNS.fillers, ' ');\n      if (this.config.removeRedundantIntros) txt = txt.replace(TokenSaver.PATTERNS.redundantIntros, '');\n  \n      // trim / collapse whitespace\n      txt = txt.trim().replace(/\\s+/g, ' ');\n      // fix spacing before punctuation\n      txt = txt.replace(/\\s([.,!?;:])/g, '$1');\n      // ✂️  orphan “ ! ” or “ ? ” that was left after deleting a word,\n      // but keep legit punctuation (no preceding space → keep it).\n      txt = txt.replace(/\\s[!?]+$/, '');\n  \n      if (txt) txt = txt[0].toUpperCase() + txt.slice(1);\n      return txt;\n    }\n  \n    _tokens(str) {\n      return Math.ceil(str.length / this.config.tokenCharRatio);\n    }\n  \n    process(prompt) {\n      const cleaned = this.clean(prompt);\n      return {\n        original: prompt,\n        cleaned,\n        charsSaved: prompt.length - cleaned.length,\n        estimatedTokensSaved: this._tokens(prompt) - this._tokens(cleaned)\n      };\n    }\n  }\n  \n  export default TokenSaver;  "],"names":["TokenSaver","static","removePoliteness","removeFillers","removeRedundantIntros","tokenCharRatio","politeness","fillers","redundantIntros","constructor","options","this","config","DEFAULT_CONFIG","clean","prompt","txt","replace","PATTERNS","trim","toUpperCase","slice","_tokens","str","Math","ceil","length","process","cleaned","original","charsSaved","estimatedTokensSaved"],"mappings":"aAGA,MAAMA,EACFC,sBAAwB,CACtBC,kBAAkB,EAClBC,eAAe,EACfC,uBAAuB,EACvBC,eAAgB,GAIlBJ,gBAAkB,CAChBK,WACE,0LACFC,QACE,oGACFC,gBACE,8QAGJ,WAAAC,CAAYC,EAAU,IACpBC,KAAKC,OAAS,IAAKZ,EAAWa,kBAAmBH,EACvD,CAEI,KAAAI,CAAMC,EAAS,IACb,IAAIC,EAAM,GAAGD,IAeb,OAbIJ,KAAKC,OAAOV,mBAAkBc,EAAMA,EAAIC,QAAQjB,EAAWkB,SAASZ,WAAY,MAChFK,KAAKC,OAAOT,gBAAea,EAAMA,EAAIC,QAAQjB,EAAWkB,SAASX,QAAS,MAC1EI,KAAKC,OAAOR,wBAAuBY,EAAMA,EAAIC,QAAQjB,EAAWkB,SAASV,gBAAiB,KAG9FQ,EAAMA,EAAIG,OAAOF,QAAQ,OAAQ,KAEjCD,EAAMA,EAAIC,QAAQ,gBAAiB,MAGnCD,EAAMA,EAAIC,QAAQ,WAAY,IAE1BD,IAAKA,EAAMA,EAAI,GAAGI,cAAgBJ,EAAIK,MAAM,IACzCL,CACb,CAEI,OAAAM,CAAQC,GACN,OAAOC,KAAKC,KAAKF,EAAIG,OAASf,KAAKC,OAAOP,eAChD,CAEI,OAAAsB,CAAQZ,GACN,MAAMa,EAAUjB,KAAKG,MAAMC,GAC3B,MAAO,CACLc,SAAUd,EACVa,UACAE,WAAYf,EAAOW,OAASE,EAAQF,OACpCK,qBAAsBpB,KAAKW,QAAQP,GAAUJ,KAAKW,QAAQM,GAElE"}