Remove from* variants, move fromString to stringTo (#233)

* Remove from* variants, move fromString to stringTo

* Bump
This commit is contained in:
Jaco Greeff
2018-10-18 10:30:14 +02:00
committed by GitHub
parent 35579c4d70
commit 57eddba598
56 changed files with 69 additions and 378 deletions
+26
View File
@@ -0,0 +1,26 @@
// Copyright 2017-2018 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import './polyfill/textEncoder';
const encoder = new TextEncoder();
/**
* @name stringToU8a
* @signature stringToU8a (value?: string): UInt8Array
* @summary Creates a Uint8Array object from a utf-8 string.
* @description
* String input values return the actual encoded `UInt8Array`. `null` or `undefined` values returns an empty encoded array.
* @example
* import { stringToU8a } from '@polkadot/util';
*
* stringToU8a('hello'); // [0x68, 0x65, 0x6c, 0x6c, 0x6f]
*/
export default function stringToU8a (value?: string): Uint8Array {
if (!value) {
return new Uint8Array([]);
}
return encoder.encode(value);
}