Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
831 bytes
|
Line | |
---|
1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | exports.strToEncoding = exports.assertEncoding = exports.ENCODING_UTF8 = void 0;
|
---|
4 | var buffer_1 = require("./internal/buffer");
|
---|
5 | var errors = require("./internal/errors");
|
---|
6 | exports.ENCODING_UTF8 = 'utf8';
|
---|
7 | function assertEncoding(encoding) {
|
---|
8 | if (encoding && !buffer_1.Buffer.isEncoding(encoding))
|
---|
9 | throw new errors.TypeError('ERR_INVALID_OPT_VALUE_ENCODING', encoding);
|
---|
10 | }
|
---|
11 | exports.assertEncoding = assertEncoding;
|
---|
12 | function strToEncoding(str, encoding) {
|
---|
13 | if (!encoding || encoding === exports.ENCODING_UTF8)
|
---|
14 | return str; // UTF-8
|
---|
15 | if (encoding === 'buffer')
|
---|
16 | return new buffer_1.Buffer(str); // `buffer` encoding
|
---|
17 | return new buffer_1.Buffer(str).toString(encoding); // Custom encoding
|
---|
18 | }
|
---|
19 | exports.strToEncoding = strToEncoding;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.