Sha256: 45f0516a0269abed5c1732bde4b5b721f190af2d77cb9d7d8cf67b2a950cb01c

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

// In order to properly parse ruby code, we need to tell the ruby process to
// parse using UTF-8. Unfortunately, the way that you accomplish this looks
// differently depending on your platform.
/* istanbul ignore next */
function getLang() {
  const { env, platform } = process;
  const envValue = env.LC_ALL || env.LC_CTYPE || env.LANG;

  // If an env var is set for the locale that already includes UTF-8 in the
  // name, then assume we can go with that.
  if (envValue && envValue.includes("UTF-8")) {
    return envValue;
  }

  // Otherwise, we're going to guess which encoding to use based on the system.
  // This is probably not the best approach in the world, as you could be on
  // linux and not have C.UTF-8, but in that case you're probably passing an env
  // var for it. This object below represents all of the possible values of
  // process.platform per:
  // https://nodejs.org/api/process.html#process_process_platform
  return {
    aix: "C.UTF-8",
    darwin: "en_US.UTF-8",
    freebsd: "C.UTF-8",
    linux: "C.UTF-8",
    openbsd: "C.UTF-8",
    sunos: "C.UTF-8",
    win32: ".UTF-8"
  }[platform];
}

module.exports = getLang;

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
prettier-1.5.4 src/parser/getLang.js
prettier-1.5.3 src/parser/getLang.js
prettier-1.5.2 src/parser/getLang.js
prettier-1.5.1 src/parser/getLang.js
prettier-1.5.0 src/parser/getLang.js
prettier-1.4.0 src/parser/getLang.js