@cardcore/util
Advanced tools
Comparing version 0.0.1-1f746c46 to 0.0.1-4a0572cd
@@ -54,2 +54,22 @@ "use strict"; | ||
}); | ||
var _box = require("./box"); | ||
Object.defineProperty(exports, "Box", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_box).default; | ||
} | ||
}); | ||
var _hashState = require("./hash-state"); | ||
Object.defineProperty(exports, "hashState", { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_hashState).default; | ||
} | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
//# sourceMappingURL=index.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
var _ssbKeys = require("ssb-keys"); | ||
var _ssbKeys = require("@streamplace/ssb-keys"); | ||
@@ -38,6 +38,5 @@ var _ssbKeys2 = _interopRequireDefault(_ssbKeys); | ||
if (!seed) { | ||
seed = _ssbKeys2.default.hash("" + Math.random()); | ||
if (seed) { | ||
this.setSeed(seed); | ||
} | ||
this.setSeed(seed); | ||
} | ||
@@ -68,2 +67,5 @@ | ||
value: function next() { | ||
if (!this.seed) { | ||
throw new Error("tried to use RNG without providing a seed!"); | ||
} | ||
return this.seed = this.seed * 16807 % 2147483647; | ||
@@ -76,2 +78,7 @@ } | ||
} | ||
}, { | ||
key: "clearSeed", | ||
value: function clearSeed() { | ||
this.seed = null; | ||
} | ||
}]); | ||
@@ -78,0 +85,0 @@ |
@@ -6,4 +6,13 @@ "use strict"; | ||
}); | ||
exports.uid = exports.traverseSecret = exports.getRightPlayer = exports.getLeftPlayer = exports.rotateArray = undefined; | ||
exports.range = range; | ||
var _randomUtil = require("./random-util"); | ||
var _ssbKeys = require("@streamplace/ssb-keys"); | ||
var _ssbKeys2 = _interopRequireDefault(_ssbKeys); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
@@ -41,2 +50,24 @@ | ||
/** | ||
* Get the player to the left of this one | ||
*/ | ||
var getLeftPlayer = exports.getLeftPlayer = function getLeftPlayer(playerId, players) { | ||
var index = players.indexOf(playerId); | ||
if (index === 0) { | ||
return players[players.length - 1]; | ||
} | ||
return players[index - 1]; | ||
}; | ||
/** | ||
* Get the player to the right of this one | ||
*/ | ||
var getRightPlayer = exports.getRightPlayer = function getRightPlayer(playerId, players) { | ||
var index = players.indexOf(playerId); | ||
if (index === players.length - 1) { | ||
return players[0]; | ||
} | ||
return players[index + 1]; | ||
}; | ||
var traverseSecret = exports.traverseSecret = function traverseSecret(secret, secrets) { | ||
@@ -52,12 +83,5 @@ if (!secret || !secret.secret) { | ||
/** | ||
* id-generation function that assumes that all users will execute it in the _exact_ same order. | ||
* this is.... hopefully reasonable. | ||
*/ | ||
var cur = 0; | ||
var uid = exports.uid = function uid() { | ||
var res = "id-" + cur; | ||
cur += 1; | ||
return res; | ||
return "id-" + _randomUtil.rando.next(); | ||
}; | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "@cardcore/util", | ||
"version": "0.0.1-1f746c46", | ||
"version": "0.0.1-4a0572cd", | ||
"description": "various streamcards utilities", | ||
@@ -13,3 +13,6 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "1f746c46c9911e36a1e9be89edf6da902e8ff20f" | ||
"dependencies": { | ||
"@streamplace/ssb-keys": "^7.0.16" | ||
}, | ||
"gitHead": "4a0572cd286ae86d011a80c5b81ac8fcfe50072b" | ||
} |
@@ -5,1 +5,3 @@ export * from "./target-helper"; | ||
export * from "./constants"; | ||
export { default as Box } from "./box"; | ||
export { default as hashState } from "./hash-state"; |
// very simple PRNG from here https://gist.github.com/blixt/f17b47c62508be59987b | ||
import ssbKeys from "ssb-keys"; | ||
import ssbKeys from "@streamplace/ssb-keys"; | ||
@@ -14,6 +14,5 @@ export function shuffle(arr, func = Math.random) { | ||
constructor(seed) { | ||
if (!seed) { | ||
seed = ssbKeys.hash(`${Math.random()}`); | ||
if (seed) { | ||
this.setSeed(seed); | ||
} | ||
this.setSeed(seed); | ||
} | ||
@@ -40,2 +39,5 @@ | ||
next() { | ||
if (!this.seed) { | ||
throw new Error("tried to use RNG without providing a seed!"); | ||
} | ||
return (this.seed = (this.seed * 16807) % 2147483647); | ||
@@ -47,4 +49,8 @@ } | ||
} | ||
clearSeed() { | ||
this.seed = null; | ||
} | ||
} | ||
export const rando = new RandomUtil(); |
@@ -0,1 +1,4 @@ | ||
import { rando } from "./random-util"; | ||
import ssbKeys from "@streamplace/ssb-keys"; | ||
/** | ||
@@ -27,2 +30,24 @@ * Like Python's range. Get an array of numbers from 0 to n. | ||
/** | ||
* Get the player to the left of this one | ||
*/ | ||
export const getLeftPlayer = (playerId, players) => { | ||
const index = players.indexOf(playerId); | ||
if (index === 0) { | ||
return players[players.length - 1]; | ||
} | ||
return players[index - 1]; | ||
}; | ||
/** | ||
* Get the player to the right of this one | ||
*/ | ||
export const getRightPlayer = (playerId, players) => { | ||
const index = players.indexOf(playerId); | ||
if (index === players.length - 1) { | ||
return players[0]; | ||
} | ||
return players[index + 1]; | ||
}; | ||
export const traverseSecret = (secret, secrets) => { | ||
@@ -38,11 +63,4 @@ if (!secret || !secret.secret) { | ||
/** | ||
* id-generation function that assumes that all users will execute it in the _exact_ same order. | ||
* this is.... hopefully reasonable. | ||
*/ | ||
let cur = 0; | ||
export const uid = () => { | ||
let res = `id-${cur}`; | ||
cur += 1; | ||
return res; | ||
return `id-${rando.next()}`; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44830
22
783
1
+ Added@streamplace/chloride@2.2.12(transitive)
+ Added@streamplace/private-box@0.2.1(transitive)
+ Added@streamplace/ssb-keys@7.0.21(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedchloride-test@1.2.4(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addeded2curve@0.1.4(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-electron@2.2.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedjson-buffer@2.0.11(transitive)
+ Addedjson-stable-stringify@1.2.1(transitive)
+ Addedjsonify@0.0.1(transitive)
+ Addedlibsodium@0.7.15(transitive)
+ Addedlibsodium-wrappers@0.7.15(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsha.js@2.4.112.4.5(transitive)
+ Addedsodium-browserify@1.3.0(transitive)
+ Addedsodium-browserify-tweetnacl@0.2.6(transitive)
+ Addedsodium-chloride@1.1.2(transitive)
+ Addedtweetnacl@0.14.51.0.3(transitive)
+ Addedtweetnacl-auth@0.3.1(transitive)