winchars.js 533 B

1234567891011121314151617181920212223
  1. 'use strict'
  2. // When writing files on Windows, translate the characters to their
  3. // 0xf000 higher-encoded versions.
  4. const raw = [
  5. '|',
  6. '<',
  7. '>',
  8. '?',
  9. ':'
  10. ]
  11. const win = raw.map(char =>
  12. String.fromCharCode(0xf000 + char.charCodeAt(0)))
  13. const toWin = new Map(raw.map((char, i) => [char, win[i]]))
  14. const toRaw = new Map(win.map((char, i) => [char, raw[i]]))
  15. module.exports = {
  16. encode: s => raw.reduce((s, c) => s.split(c).join(toWin.get(c)), s),
  17. decode: s => win.reduce((s, c) => s.split(c).join(toRaw.get(c)), s)
  18. }