summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/pacote/lib/util/read-json.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/pacote/lib/util/read-json.js')
-rw-r--r--deps/npm/node_modules/pacote/lib/util/read-json.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/deps/npm/node_modules/pacote/lib/util/read-json.js b/deps/npm/node_modules/pacote/lib/util/read-json.js
new file mode 100644
index 0000000000..32fffbc537
--- /dev/null
+++ b/deps/npm/node_modules/pacote/lib/util/read-json.js
@@ -0,0 +1,15 @@
+'use strict'
+
+module.exports = function (content) {
+ // Code also yanked from read-package-json.
+ function stripBOM (content) {
+ content = content.toString()
+ // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
+ // because the buffer-to-string conversion in `fs.readFileSync()`
+ // translates it to FEFF, the UTF-16 BOM.
+ if (content.charCodeAt(0) === 0xFEFF) return content.slice(1)
+ return content
+ }
+
+ return JSON.parse(stripBOM(content))
+}