-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
71 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@kenan" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
node_modules | ||
npm-debug.log | ||
npm-debug.log | ||
*.d.ts | ||
!typings/*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,53 @@ | ||
var test = require('tape'); | ||
var isFunction = require('lodash.isfunction'); | ||
var forEach = require('lodash.foreach'); | ||
var isBrowser = require('is-browser'); | ||
const test = require('tape'); | ||
const isFunction = require('lodash.isfunction'); | ||
const isBrowser = require('is-browser'); | ||
|
||
var getRandomValues = require('../'); | ||
const getRandomValues = require('../'); | ||
|
||
test('exports a function', function(t) { | ||
t.plan(1); | ||
t.ok(isFunction(getRandomValues)); | ||
}); | ||
|
||
test('does not cast buffer', function(t) { | ||
var TYPES = [ | ||
// eslint-disable-next-line max-len | ||
/** @type {readonly (Uint8ArrayConstructor | Int8ArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor)[]} */ | ||
let TYPES = [ | ||
Uint8Array | ||
]; | ||
|
||
if (isBrowser) { | ||
Array.prototype.push.apply(TYPES, [ | ||
TYPES = [ | ||
...TYPES, | ||
Int8Array, | ||
Int16Array, | ||
Uint16Array, | ||
Int32Array, | ||
Uint32Array | ||
]); | ||
]; | ||
} | ||
|
||
t.plan(TYPES.length * 3); | ||
|
||
forEach(TYPES, function(Type) { | ||
var buf = new Type(8); | ||
for (const Type of TYPES) { | ||
const buf = new Type(8); | ||
t.doesNotThrow(function() { | ||
getRandomValues(buf); | ||
}); | ||
t.equal(buf.constructor, Type); | ||
t.equal(buf.length, 8); | ||
}); | ||
} | ||
}); | ||
|
||
test('throws on length >65536', function(t) { | ||
t.plan(1); | ||
t.throws(function() { | ||
getRandomValues(new Uint8Array(65537)); | ||
}, new RegExp(/QuotaExceededError/)); | ||
}, /QuotaExceededError/); | ||
}); | ||
|
||
test('returns argument', function(t) { | ||
t.plan(1); | ||
var argument = new Uint8Array(1024); | ||
const argument = new Uint8Array(1024); | ||
t.equal(getRandomValues(argument), argument); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "@tsconfig/node14/tsconfig.json", | ||
"compilerOptions": { | ||
"lib": ["es2020", "dom"], | ||
"allowJs": true, | ||
"checkJs": true, | ||
"declaration": true, | ||
"emitDeclarationOnly": true | ||
}, | ||
"include": ["typings", "test/**/*.js", "*.js"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare module 'global/window' { | ||
interface GlobalWindow extends Window { | ||
msCrypto?: Crypto | ||
} | ||
const globalWindow: GlobalWindow; | ||
export = globalWindow; | ||
} |