main.js (1748B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2021 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var isBigUint64Array = require( './../../is-biguint64array' ); 24 var isBigInt = require( './../../is-bigint' ); 25 var GlobalBigUint64Array = require( './biguint64array.js' ); 26 27 28 // VARIABLES // 29 30 var MAX_SIGNED_INT64 = '9223372036854775807'; // 2**63 - 1 31 var MAX_SIGNED_INT64_P2 = '9223372036854775809'; 32 33 34 // MAIN // 35 36 /** 37 * Tests for native `BigUint64Array` support. 38 * 39 * @returns {boolean} boolean indicating if an environment has `BigUint64Array` support 40 * 41 * @example 42 * var bool = hasBigUint64ArraySupport(); 43 * // returns <boolean> 44 */ 45 function hasBigUint64ArraySupport() { 46 var arr; 47 if ( typeof GlobalBigUint64Array !== 'function' ) { 48 return false; 49 } 50 // Test basic support... 51 try { 52 arr = new GlobalBigUint64Array([ 53 MAX_SIGNED_INT64, 54 MAX_SIGNED_INT64_P2 55 ]); 56 return ( 57 isBigUint64Array( arr ) && 58 isBigInt( arr[ 0 ] ) && 59 arr[ 0 ].toString() === MAX_SIGNED_INT64 && 60 isBigInt( arr[ 1 ] ) && 61 arr[ 1 ].toString() === MAX_SIGNED_INT64_P2 62 ); 63 } catch ( err ) { // eslint-disable-line no-unused-vars 64 return false; 65 } 66 } 67 68 69 // EXPORTS // 70 71 module.exports = hasBigUint64ArraySupport;