Skip to content

Downloading the Source Code

gignu edited this page May 30, 2022 · 2 revisions

Important Steps

  1. Create a new folder called lib inside your root directory
  2. Inside lib create a new file and call it language-encoding.min.js
  3. Make sure the encoding of your newly created file is either UTF-8 or UTF-8 with BOM before proceeding!
  4. Go to https://unpkg.com/detect-file-encoding-and-language/umd/language-encoding.min.js and copy the code
  5. Paste it into language-encoding.min.js and save it
  6. Use the code below to load language-encoding.min.js via the <script> tag.

Usage

// index.html
<body>
  <input type="file" id="my-input-field" />
  <script src="lib/language-encoding.min.js"></script>
  <script src="app.js"></script>
</body>

// app.js
document.getElementById("my-input-field").addEventListener("change", (e) => {
  const file = e.target.files[0];
  languageEncoding(file).then((fileInfo) => console.log(fileInfo));
  // Possible result: { language: english, encoding: UTF-8, confidence: { encoding: 1, language: 1 } }
});
Clone this wiki locally