Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
@stdlib/buffer-from-string
Advanced tools
Allocate a buffer containing a provided string.
npm install @stdlib/buffer-from-string
var string2buffer = require( '@stdlib/buffer-from-string' );
Allocates a buffer containing a provided string
.
var buf = string2buffer( 'beep boop' );
// returns <Buffer>
The default character encoding is utf8
. To specify an alternative encoding, provide an encoding
argument.
var buf = string2buffer( '7468697320697320612074c3a97374', 'hex' );
// returns <Buffer>
The following encodings
are supported:
utf8
(utf-8
)hex
binary
ascii
ucs2
base64
var randu = require( '@stdlib/random-base-randu' );
var randint = require( '@stdlib/random-base-discrete-uniform' );
var string2buffer = require( '@stdlib/buffer-from-string' );
// Create a buffer from a string:
var buf = string2buffer( 'beep boop bop' );
console.log( buf.toString() );
// Generate random strings...
var i;
var j;
for ( i = 0; i < 100; i++ ) {
j = randint( 0, buf.length );
if ( randu() < 2/buf.length ) {
buf[ j ] = 32; // space
} else {
buf[ j ] = randint( 97, 122 );
}
console.log( buf.toString() );
}
@stdlib/buffer/ctor
: Buffer.@stdlib/buffer/from-array
: allocate a buffer using an octet array.@stdlib/buffer/from-arraybuffer
: allocate a buffer from an ArrayBuffer.@stdlib/buffer/from-buffer
: copy buffer data to a new Buffer instance.This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2022. The Stdlib Authors.
0.0.8 (2022-07-12)
No changes reported for this release.
</section> <!-- /.release --> <section class="release" id="v0.0.7">FAQs
Allocate a buffer containing a provided string.
The npm package @stdlib/buffer-from-string receives a total of 327,987 weekly downloads. As such, @stdlib/buffer-from-string popularity was classified as popular.
We found that @stdlib/buffer-from-string demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.