Skip to content
This repository was archived by the owner on Jun 12, 2026. It is now read-only.

Future Proofing

Latest

Choose a tag to compare

@eoussama eoussama released this 12 Jun 15:39

eo-translatorjs v3.1.3

πŸ› Bug Fixes

  • translateDOM operator precedence β€” the container argument was silently ignored; the method always fell back to document regardless of what was passed. Fixed with ?? null-coalescing.
  • translate() used wrong variable for language lookup β€” when options.lang was supplied the hasOwnProperty guard still checked this.language, causing incorrect fallback behaviour.
  • Error messages printed "string" instead of the actual key β€” language error messages interpolated typeof lang (always "string") rather than the key value itself.
  • add() nested traversal was fragile β€” the embedded tempDict[frag] = {} assignment inside a || expression could silently fail and the final key was set inside the loop instead of after it. Rewritten as a clean for loop.
  • extractValue used truthiness β€” falsy-but-valid translation values (0, false, "") were treated as missing. Changed to an explicit == null guard.
  • translateElement accessed .value without null-checking β€” reading .attributes["eo-translator"].value without first verifying the attribute existed could throw. All optional attribute reads are now null-guarded; passing null is a safe no-op.

πŸ”’ Security & Safety

  • assignParams RegExp injection β€” parameter key names are now escaped with key.replace(/[$()*+.?[]^{|}]/g, "\\$&") before being used in a RegExp constructor, preventing injection from keys that contain regex special characters.

♻️ Refactoring

  • Replaced all obj.hasOwnProperty(key) calls with Object.prototype.hasOwnProperty.call(obj, key) to eliminate no-prototype-builtins violations.
  • translateDOM now correctly uses DOMContainer ?? (typeof document === "object" ? document : null).
  • Error type distinction: validation errors on wrong types now throw TypeError; missing key errors throw Error.
  • Removed dead dict || {} fallback in constructor (the preceding guard already ensures dict is truthy).
  • Fixed typos: "recieved" β†’ "received", "transition" β†’ "translation" in comments and error messages.

πŸ§ͺ Tests

  • Test count: 22 β†’ 44 (+22).
  • Error-path tests migrated from try/catch + boolean flag to expect(() => …).toThrow() with message and type assertions.
  • New coverage: languages getter, isValidLanguage(), dictionary/language setters (valid & invalid), translate() with lang override, fallback option, language not found, multiple params, deeply nested keys, translateElement HTML rendering (eo-translator-html="true/false"), translateElement(null) no-op, translateDOM() on container, translateDOM() with language override.

πŸ”§ Tooling & Infrastructure

  • Migrated from npm β†’ pnpm (pnpm-lock.yaml, pnpm-workspace.yaml).
  • Added ESLint via @eoussama/dx (eslint.config.js): pnpm lint / pnpm run lint:fix.
  • All 19 audit vulnerabilities resolved β€” pnpm audit reports 0 vulnerabilities (combination of direct dependency upgrades and pnpm-workspace.yaml overrides).
  • Removed package-lock.json.

πŸ“ Documentation

  • README fully rewritten: installation (npm/pnpm/yarn + CDN), Node.js/CommonJS usage, full API reference with parameter tables and runnable examples for every method (translate, translateElement, translateDOM, add, remove, isValidLanguage, languages getter, dictionary and language properties).

🏷️ Rename

  • Project renamed from translatorjs to eo-translatorjs throughout: package name, source file (src/eo-translatorjs.js), test file (tests/eo-translatorjs.test.js), type declarations (types/eo-translatorjs.d.ts), dist output, error message prefixes ([EOTranslatorJS]), and all URLs/docs.

Full Changelog: v3.1.1...3.1.3