Socket
Socket
Sign inDemoInstall

protoblast

Package Overview
Dependencies
1
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.7.3 to 0.7.4

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## 0.7.4 (2020-10-22)
* Add `Blast.isSafari` boolean & fix detection for iPadOS 13
* Add `Crypto.nanoid(size)` to create a nano-id
* Add `Crypto.createNanoidGenerator(alphabet, default_size, rng)` to create custom nano-id generators
* Add `SeededRng#randomBytes()` so it can be used as an rng in the nano-id generator
## 0.7.3 (2020-10-08)

@@ -2,0 +9,0 @@

142

lib/crypto.js

@@ -5,3 +5,4 @@ module.exports = function BlastCrypto(Blast, Collection) {

var addRandomValues,
var public_nanoid_generator,
addRandomValues,
libcrypto,

@@ -28,3 +29,3 @@ instance;

* @since 0.1.4
* @version 0.1.4
* @version 0.7.4
*

@@ -34,3 +35,31 @@ * @return {String}

Crypto.setStatic(function uid() {
return Crypto.publicInstance().uid();
});
/**
* Get a nanoid
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.7.4
* @version 0.7.4
*
* @param {Number} size
*
* @return {String}
*/
Crypto.setStatic(function nanoid(size) {
return Crypto.publicInstance().nanoid(size);
});
/**
* Get the shared instance
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 0.7.4
* @version 0.7.4
*
* @return {Crypto}
*/
Crypto.setStatic(function publicInstance() {
if (instance == null) {

@@ -41,3 +70,3 @@ instance = new Crypto();

return instance.uid();
return instance;
});

@@ -61,2 +90,56 @@

/**
* Create a random nanoid generator
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 0.7.4
* @version 0.7.4
*
* @param {String} alphabet
* @param {Number} default_size
* @param {Object} random
*
* @return {Function}
*/
Crypto.setStatic(function createNanoidGenerator(alphabet, default_size, random) {
let alphabet_length = alphabet.length,
mask = (2 << (31 - Math.clz32((alphabet_length - 1) | 1))) - 1,
default_step = Math.ceil((1.6 * mask * default_size) / alphabet_length);
if (!random) {
random = Crypto.publicInstance();
}
return function generateNanoId(size) {
let step;
if (!size) {
size = default_size;
}
if (size == default_size) {
step = default_step;
} else {
step = Math.ceil((1.6 * mask * size) / alphabet_length);
}
let bytes,
id = '',
i;
while (true) {
bytes = random.randomBytes(step);
i = step;
while (i--) {
id += alphabet[bytes[i] & mask] || '';
if (id.length === +size) return id;
}
}
}
});
/**
* Request new random numbers

@@ -126,2 +209,55 @@ *

/**
* Generate a random string
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 0.7.4
* @version 0.7.4
*
* @param {Number} bytesize
* @param {Function} callback
*
* @return {Buffer}
*/
Crypto.setMethod(function randomBytes(bytesize, callback) {
return Crypto.randomBytes(bytesize, callback);
});
/**
* Generate a random string and convert it as Base64
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.7.4
* @version 0.7.4
*
* @param {Number} bytesize
* @param {Function} callback Optional callback
*
* @return {String}
*/
Crypto.setMethod(function randomHex(bytesize, callback) {
return Crypto.randomHex(bytesize, callback);
});
/**
* Get a nano-id
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 0.7.4
* @version 0.7.4
*
* @param {Number} length
*
* @return {String}
*/
Crypto.setMethod(function nanoid(length) {
if (!public_nanoid_generator) {
// The default alphabet is like this for gzip reasons ^^
public_nanoid_generator = Crypto.createNanoidGenerator('ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW', 21);
}
return public_nanoid_generator(length);
});
if (Blast.isNode) {

@@ -128,0 +264,0 @@ // PROTOBLAST START CUT

18

lib/init.js

@@ -38,9 +38,10 @@ module.exports = function BlastInitLoader(modifyPrototype) {

* @since 0.6.6
* @version 0.6.6
* @version 0.7.4
*
* @param {String} useragent
* @param {String} useragent The useragent string
* @param {Object} navigator Optional navigator object
*
* @return {Object}
*/
function parseUseragent(ua) {
function parseUseragent(ua, navigator) {

@@ -132,2 +133,7 @@ if (!ua) {

if (navigator && (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) {
platform = 'mobile';
os = 'ios';
}
if (platform != 'desktop') {

@@ -185,2 +191,5 @@ if (~ua.indexOf('iphone') || ~ua.indexOf('ipad') || ~ua.indexOf('ipod')) {

// Is it running Safari?
Blast.isSafari = false;
// If it's a browser, is it IE?

@@ -215,3 +224,3 @@ Blast.isIE = false;

ua = window.navigator.userAgent;
ua = parseUseragent(window.navigator.userAgent);
ua = parseUseragent(window.navigator.userAgent, window.navigator);

@@ -227,2 +236,3 @@ Blast.userAgent = ua;

Blast.isiOS = ua.os == 'ios';
Blast.isSafari = ua.family == 'safari';
Blast.isWebview = ua.webview;

@@ -229,0 +239,0 @@ Blast.isChrome = ua.family == 'chrome';

@@ -138,2 +138,29 @@ module.exports = function BlastSeededRandom(Blast, Collection) {

/**
* Get an array of random numbers
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 0.7.4
* @version 0.7.4
*
* @param {Number} size How many bytes to return
* @param {Function} callback Optional callback
*
* @return {Array}
*/
Seeded.setMethod(function randomBytes(size, callback) {
let result = [];
while (size--) {
result.push(~~(this.random() * 256));
}
if (callback) {
callback(null, result);
}
return result;
});
};
{
"name": "protoblast",
"description": "Native object expansion library",
"version": "0.7.3",
"version": "0.7.4",
"author": "Jelle De Loecker <jelle@elevenways.be>",

@@ -6,0 +6,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc