@mailchain/encoding
Advanced tools
| function encodeAscii(input) { | ||
| return Buffer.from(input).toString('ascii'); | ||
| } | ||
| function decodeAscii(input) { | ||
| if (!isAscii(input)) | ||
| throw new Error('Input is not ASCII'); | ||
| return new Uint8Array(Buffer.from(input, 'ascii')); | ||
| } | ||
| function isAscii(str) { | ||
| // eslint-disable-next-line no-control-regex | ||
| return /^[\x00-\x7F]+$/.test(str); | ||
| } | ||
| export { decodeAscii, encodeAscii, isAscii }; |
| 'use strict'; | ||
| function encodeAscii(input) { | ||
| return Buffer.from(input).toString('ascii'); | ||
| } | ||
| function decodeAscii(input) { | ||
| if (!isAscii(input)) | ||
| throw new Error('Input is not ASCII'); | ||
| return new Uint8Array(Buffer.from(input, 'ascii')); | ||
| } | ||
| function isAscii(str) { | ||
| // eslint-disable-next-line no-control-regex | ||
| return /^[\x00-\x7F]+$/.test(str); | ||
| } | ||
| exports.decodeAscii = decodeAscii; | ||
| exports.encodeAscii = encodeAscii; | ||
| exports.isAscii = isAscii; |
| export declare function encodeAscii(input: Uint8Array): string; | ||
| export declare function decodeAscii(input: string): Uint8Array; | ||
| export declare function isAscii(str: string): boolean; |
| export {}; |
+1
-0
@@ -10,1 +10,2 @@ export { EncodingTypes } from './consts.js'; | ||
| export { decodeUtf8, encodeUtf8 } from './utf8.js'; | ||
| export { decodeAscii, encodeAscii, isAscii } from './ascii.js'; |
+4
-0
@@ -12,2 +12,3 @@ 'use strict'; | ||
| var utf8 = require('./utf8.js'); | ||
| var ascii = require('./ascii.js'); | ||
@@ -42,1 +43,4 @@ | ||
| exports.encodeUtf8 = utf8.encodeUtf8; | ||
| exports.decodeAscii = ascii.decodeAscii; | ||
| exports.encodeAscii = ascii.encodeAscii; | ||
| exports.isAscii = ascii.isAscii; |
+1
-1
| { | ||
| "name": "@mailchain/encoding", | ||
| "version": "0.25.0", | ||
| "version": "0.26.0", | ||
| "description": "Mailchain encoding tools", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
+1
-0
@@ -10,1 +10,2 @@ export * from './consts'; | ||
| export * from './utf8'; | ||
| export * from './ascii'; |
25344
5.42%42
10.53%671
6.17%