Socket
Socket
Sign inDemoInstall

@aryth/rand

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aryth/rand - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

66

dist/index.cjs.js

@@ -5,2 +5,3 @@ 'use strict';

var swap = require('@vect/swap');
var comparer = require('@aryth/comparer');

@@ -56,6 +57,12 @@

const swap = function (i, j) {
const temp = this[i];
this[i] = this[j];
return this[j] = temp;
const flopGenerator = function* (ar, df) {
var _df, _ar;
let l = ar.length;
while (--l >= 0) yield swap.swap.call(ar, rand(l), l);
df = (_df = df) !== null && _df !== void 0 ? _df : (_ar = ar, flop(_ar));
while (true) yield df;
};

@@ -67,2 +74,3 @@

* @param {number} [size] - if omitted, size will be keys.length
* @deprecated shuffle under @aryth/rand will be out-of-maintenance soon, please switch to @aryth/shuffle
* @returns {Array} mutated array

@@ -75,55 +83,10 @@ */

for (--l; l >= lo; l--) swap.call(ve, l, rand(l));
while (--l >= lo) swap.swap.call(ve, l, rand(l));
return lo ? (ve.splice(0, lo), ve) : ve;
};
/**
*
* Object keys can be set via 'this.keys'
* Default keys are Object.keys(o), the enumerable list of o's keys.
* @param {Object} o
* @param {number} [size] - if omitted, size will be keys.length
* @returns {Object} new object
*/
const shuffleObject = function (o, size) {
const keys = (this === null || this === void 0 ? void 0 : this.keys) || Object.keys(o);
let l = keys.length,
k;
const lo = comparer.max(0, l - (size !== null && size !== void 0 ? size : l)),
rs = {};
for (--l; l >= lo; l--) rs[k = swap.call(keys, rand(l), l)] = o[k];
return rs;
};
function indexShuffler(ar) {
let length = this.length || ar.length;
let size = comparer.min(length, this.size);
const vec = Array(size);
for (let i = 0, set = new Set(), rn; i < size; i++) {
do {
var _length;
rn = (_length = length, rand(_length));
} while (set.has(rn));
set.add(rn);
vec[i] = rn;
}
return vec;
}
const shuffler = function (ar) {
return indexShuffler.call(this, ar).map(i => ar[i]);
};
const Shuffler = size => shuffler.bind({
size
});
exports.Shuffler = Shuffler;
exports.flop = flop;
exports.flopEntry = flopEntry;
exports.flopGenerator = flopGenerator;
exports.flopIndex = flopIndex;

@@ -137,2 +100,1 @@ exports.flopKey = flopKey;

exports.shuffle = shuffle;
exports.shuffleObject = shuffleObject;

@@ -1,2 +0,3 @@

import { max, min } from '@aryth/comparer';
import { swap } from '@vect/swap';
import { max } from '@aryth/comparer';

@@ -51,6 +52,12 @@ const {

const swap = function (i, j) {
const temp = this[i];
this[i] = this[j];
return this[j] = temp;
const flopGenerator = function* (ar, df) {
var _df, _ar;
let l = ar.length;
while (--l >= 0) yield swap.call(ar, rand(l), l);
df = (_df = df) !== null && _df !== void 0 ? _df : (_ar = ar, flop(_ar));
while (true) yield df;
};

@@ -62,2 +69,3 @@

* @param {number} [size] - if omitted, size will be keys.length
* @deprecated shuffle under @aryth/rand will be out-of-maintenance soon, please switch to @aryth/shuffle
* @returns {Array} mutated array

@@ -70,52 +78,7 @@ */

for (--l; l >= lo; l--) swap.call(ve, l, rand(l));
while (--l >= lo) swap.call(ve, l, rand(l));
return lo ? (ve.splice(0, lo), ve) : ve;
};
/**
*
* Object keys can be set via 'this.keys'
* Default keys are Object.keys(o), the enumerable list of o's keys.
* @param {Object} o
* @param {number} [size] - if omitted, size will be keys.length
* @returns {Object} new object
*/
const shuffleObject = function (o, size) {
const keys = (this === null || this === void 0 ? void 0 : this.keys) || Object.keys(o);
let l = keys.length,
k;
const lo = max(0, l - (size !== null && size !== void 0 ? size : l)),
rs = {};
for (--l; l >= lo; l--) rs[k = swap.call(keys, rand(l), l)] = o[k];
return rs;
};
function indexShuffler(ar) {
let length = this.length || ar.length;
let size = min(length, this.size);
const vec = Array(size);
for (let i = 0, set = new Set(), rn; i < size; i++) {
do {
var _length;
rn = (_length = length, rand(_length));
} while (set.has(rn));
set.add(rn);
vec[i] = rn;
}
return vec;
}
const shuffler = function (ar) {
return indexShuffler.call(this, ar).map(i => ar[i]);
};
const Shuffler = size => shuffler.bind({
size
});
export { Shuffler, flop, flopEntry, flopIndex, flopKey, flopValue, rand, randInt, randIntBetw, randLongStr, shuffle, shuffleObject };
export { flop, flopEntry, flopGenerator, flopIndex, flopKey, flopValue, rand, randInt, randIntBetw, randLongStr, shuffle };
{
"name": "@aryth/rand",
"version": "0.0.12",
"version": "0.0.13",
"description": "A math util library",

@@ -18,3 +18,4 @@ "main": "dist/index.cjs.js",

"dependencies": {
"@aryth/comparer": "^0.0.12"
"@aryth/comparer": "^0.0.13",
"@vect/swap": "^0.1.12"
},

@@ -36,3 +37,3 @@ "repository": {

"homepage": "https://github.com/hoyeungw/aryth#readme",
"gitHead": "2c03e9e9a49eb2eff77e5550acbd1d75074cd054"
"gitHead": "19efab02effe4edb219c004bb4cbcb6ee2cf4808"
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc