|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# base64ToUint8Array |
| 22 | + |
| 23 | +> Convert a Base64-encoded string to a [Uint8Array][@stdlib/array/uint8]. |
| 24 | +
|
| 25 | +<!-- Package usage documentation. --> |
| 26 | + |
| 27 | +<section class="usage"> |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +<!-- eslint-disable stdlib/no-redeclare --> |
| 32 | + |
| 33 | +```javascript |
| 34 | +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); |
| 35 | +``` |
| 36 | + |
| 37 | +#### base64ToUint8Array( str ) |
| 38 | + |
| 39 | +Converts a base64-encoded string to a [Uint8Array][@stdlib/array/uint8]. |
| 40 | + |
| 41 | +```javascript |
| 42 | +var string2buffer = require( '@stdlib/buffer/from-string' ); |
| 43 | + |
| 44 | +var str = string2buffer( 'Hello World!' ).toString( 'base64' ); |
| 45 | +// returns 'SGVsbG8gV29ybGQh' |
| 46 | + |
| 47 | +var out = base64ToUint8Array( str ); |
| 48 | +// returns <Uint8Array>[ 72, 101, ... ] |
| 49 | +``` |
| 50 | + |
| 51 | +</section> |
| 52 | + |
| 53 | +<!-- /.usage --> |
| 54 | + |
| 55 | +<section class="notes"> |
| 56 | + |
| 57 | +## Notes |
| 58 | + |
| 59 | +- The function returns `null` when provided a string containing non-ASCII characters. |
| 60 | + |
| 61 | +</section> |
| 62 | + |
| 63 | +<!-- /.notes --> |
| 64 | + |
| 65 | +<!-- Package usage examples. --> |
| 66 | + |
| 67 | +<section class="examples"> |
| 68 | + |
| 69 | +## Examples |
| 70 | + |
| 71 | +```javascript |
| 72 | +var string2buffer = require( '@stdlib/buffer/from-string' ); |
| 73 | +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); |
| 74 | + |
| 75 | +var buf = string2buffer( 'Hello World!' ).toString( 'base64' ); |
| 76 | +// returns 'SGVsbG8gV29ybGQh' |
| 77 | + |
| 78 | +var arr = base64ToUint8Array( buf ); |
| 79 | +// returns <Uint8Array> |
| 80 | + |
| 81 | +buf = string2buffer( 'HELLO WORLD!' ).toString( 'base64' ); |
| 82 | +// returns 'SEVMTE8gV09STEQh' |
| 83 | + |
| 84 | +arr = base64ToUint8Array( buf ); |
| 85 | +// returns <Uint8Array> |
| 86 | + |
| 87 | +buf = string2buffer( 'To be, or not to be: that is the question.' ).toString( 'base64' ); |
| 88 | +// returns 'VG8gYmUsIG9yIG5vdCB0byBiZTogdGhhdCBpcyB0aGUgcXVlc3Rpb24u' |
| 89 | + |
| 90 | +arr = base64ToUint8Array( buf ); |
| 91 | +// returns <Uint8Array> |
| 92 | +``` |
| 93 | + |
| 94 | +</section> |
| 95 | + |
| 96 | +<!-- /.examples --> |
| 97 | + |
| 98 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 99 | + |
| 100 | +<section class="related"> |
| 101 | + |
| 102 | +</section> |
| 103 | + |
| 104 | +<!-- /.related --> |
| 105 | + |
| 106 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 107 | + |
| 108 | +<section class="links"> |
| 109 | + |
| 110 | +[@stdlib/array/uint8]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/uint8 |
| 111 | + |
| 112 | +<!-- <related-links> --> |
| 113 | + |
| 114 | +<!-- </related-links> --> |
| 115 | + |
| 116 | +</section> |
| 117 | + |
| 118 | +<!-- /.links --> |
0 commit comments