Best JavaScript code snippet using wpt
Int16.ts
Source:Int16.ts
1/**2 * This module provides a way to construct and work with signed, 16-bit3 * integers. They are just JavaScript`number`s under the hood, so they should4 * be comparable in performance.5 *6 * Since they are limited to 16 bits, `Int16`s are subject to overflowing if7 * the result of any operation should exceed the range of -2^15 and 2^15 - 1.8 *9 * To avoid integer overflow, see [[Int]] for arbitrary precision integers.10 *11 * Like the rest of `fp-ts-numerics`, this module exposes the `Int16` type12 * and namespace as a single declaration. It is intended to be consumed like so:13 *14 * ```ts15 * import { Int16 } from 'fp-ts-numerics'16 *17 * function isEven(n: Int16): boolean {18 * return Int16.equals(Int16.zero, Int16.mod(n, Int16.of(2)))19 * }20 * ```21 *22 * @packageDocumentation23 * @since 1.0.024 */25import { bounded, eq, option, ord, show } from 'fp-ts'26import { unsafeCoerce } from 'fp-ts/lib/function'27import { Option } from 'fp-ts/lib/Option'28import { pipe } from 'fp-ts/lib/pipeable'29import * as commutativeRing from './CommutativeRing'30import * as enum_ from './Enum'31import * as euclideanRing from './EuclideanRing'32import * as hasPow from './HasPow'33import * as hasToInt from './HasToInt'34import * as hasToRational from './HasToRational'35import { Int } from './Int'36import { Int32 } from './Int32'37import * as integral from './Integral'38import { Branded } from './Internal/Branded'39import { Natural } from './Natural'40import { NonZero } from './NonZero'41import * as numeric from './Numeric'42import { Ratio } from './Ratio'43import { Rational } from './Rational'44import * as ring from './Ring'45import * as semiring from './Semiring'46type Bounded<T> = bounded.Bounded<T>47type CommutativeRing<T> = commutativeRing.CommutativeRing<T>48type Enum<T> = enum_.Enum<T>49type Eq<T> = eq.Eq<T>50type EuclideanRing<T> = euclideanRing.EuclideanRing<T>51type HasPow<T> = hasPow.HasPow<T>52type HasToInt<T> = hasToInt.HasToInt<T>53type HasToRational<T> = hasToRational.HasToRational<T>54type Integral<T> = integral.Integral<T>55type Numeric<T> = numeric.Numeric<T>56type Ord<T> = ord.Ord<T>57type Ring<T> = ring.Ring<T>58type Semiring<T> = semiring.Semiring<T>59type Show<T> = show.Show<T>60declare const INT_16: unique symbol61/**62 * The type of signed, 16-bit integers. Subject to integer overflow.63 *64 * ```ts65 * const myInt: Int = Int(1,0,0)66 * ```67 *68 * @category Data Type69 * @since 1.0.070 */71export interface Int16 extends Branded<Int32, typeof INT_16> {}72type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 973type LeadingDigit = Exclude<Digit | -1 | -2 | -3 | -4 | -5 | -6 | -7 | -8 | -9, 0>74/**75 * A tuple of literal integers representing every valid sequence of digits for76 * [[Int16]]77 *78 * @since 1.0.079 */80export type Digits =81 | [-1 | 0 | 1]82 | [LeadingDigit]83 | [LeadingDigit, Digit]84 | [LeadingDigit, Digit, Digit]85 | [LeadingDigit, Digit, Digit, Digit]86 | [-2 | -1 | 1 | 2, Digit, Digit, Digit, Digit]87 | [-3 | 3, 0 | 1, Digit, Digit, Digit]88 | [-3 | 3, 2, Exclude<Digit, 7 | 8 | 9>, Digit, Digit]89 | [-3 | 3, 2, 7, 0 | 1 | 2 | 3 | 4 | 5, Digit]90 | [-3 | 3, 2, 7, 6, Exclude<Digit, 8 | 9>]91 | [-3, 2, 7, 6, 8]92/**93 * Constructs a signed 16-bit integer.94 *95 * - Min value: -2^1596 * - Max value: 2^15 - 197 *98 * @example99 * import { Int16 } from 'fp-ts-numerics/Int16'100 *101 * Int16.of(3,2,7,6,7)102 * // > 32767103 *104 * @category Constructor105 * @since 1.0.0106 */107export function of(zero: 0): Int16108export function of(...digits: Digits): NonZero<Int16>109export function of(...digits: Digits): Int16 | NonZero<Int16> {110 return pipe(111 digits112 .filter((x): x is Digits[number] => Number.isInteger(x))113 .map((j) => j.toString())114 .join(''),115 (str) => fromNumberLossy(+str)116 )117}118/**119 * @since 1.0.0120 */121export function isTypeOf(x: unknown): x is Int16 {122 return (123 typeof x === 'number' &&124 Number.isInteger(x) &&125 x <= toNumber(Bounded.top) &&126 x >= toNumber(Bounded.bottom)127 )128}129/**130 * @since 1.0.0131 */132export function unsafeFromNumber(n: number): Int16 {133 if (!isTypeOf(n)) {134 throw new Error(135 `${n} cannot be coerced to Int16 since it is not an integer within the bounds of ${Bounded.bottom} and ${Bounded.top}`136 )137 }138 return fromNumberLossy(n)139}140/**141 * @since 1.0.0142 */143export function fromNumberLossy(n: number): Int16 {144 return unsafeCoerce((n << 16) >> 16)145}146/**147 * @since 1.0.0148 */149export const bottom: Int16 = fromNumberLossy(-Math.pow(2, 15))150/**151 * @since 1.0.0152 */153export const top: Int16 = fromNumberLossy(Math.pow(2, 15) - 1)154// ### Transformations155/**156 * @since 1.0.0157 */158export function fromNumber(n: number): option.Option<Int16> {159 return isTypeOf(n) ? option.some(n) : option.none160}161/**162 * @since 1.0.0163 */164export function toNumber(i: Int16): number {165 return unsafeCoerce(i)166}167// ## Math Operations168/**169 * @since 1.0.0170 */171export const one: Int16 = of(1)172/**173 * @since 1.0.0174 */175export const zero: Int16 = of(0)176/**177 * @since 1.0.0178 */179export function add(a: Int16, b: Int16): Int16 {180 return fromNumberLossy(toNumber(a) + toNumber(b))181}182/**183 * @since 1.0.0184 */185export function mul(a: Int16, b: Int16): Int16 {186 return fromNumberLossy(toNumber(a) * toNumber(b))187}188/**189 * @since 1.0.0190 */191export function sub(a: Int16, b: Int16): Int16 {192 return fromNumberLossy(toNumber(a) - toNumber(b))193}194/**195 * @since 1.0.0196 */197export function degree(i: Int16): Natural {198 return unsafeCoerce(toInt(fromNumberLossy(Math.min(toNumber(top), Math.abs(toNumber(i))))))199}200/**201 * @since 1.0.0202 */203export function div(n: Int16, d: NonZero<Int16>): Int16 {204 const a = toNumber(n)205 const b = toNumber(d)206 return fromNumberLossy(b > 0 ? Math.floor(a / b) : -Math.floor(a / -b))207}208/**209 * @since 1.0.0210 */211export function mod(n: Int16, d: NonZero<Int16>): Int16 {212 const _n = toNumber(n)213 const _d = Math.abs(toNumber(d))214 return fromNumberLossy(((_n % _d) + _d) % _d)215}216/**217 * @since 1.0.0218 */219export function equals(a: Int16, b: Int16): boolean {220 return a === b221}222/**223 * @since 1.0.0224 */225export const compare = ord.contramap(toNumber)(ord.ordNumber).compare226/**227 * @since 1.0.0228 */229export function next(a: Int16): Option<Int16> {230 return ord.geq(Ord)(a, Bounded.top) ? option.none : option.some(add(a, one))231}232/**233 * @since 1.0.0234 */235export function prev(a: Int16): Option<Int16> {236 return ord.leq(Ord)(a, Bounded.bottom) ? option.none : option.some(sub(a, one))237}238/**239 * @since 1.0.0240 */241export function toRational(a: Int16): Rational {242 const intMethods = {243 ...Int.Ord,244 ...Int.EuclideanRing,245 ...Int.HasToRational,246 }247 return Ratio.of(intMethods)(Integral.toInt(a), Int.of(1))248}249/**250 * @since 1.0.0251 */252export function quot(a: Int16, b: NonZero<Int16>): Int16 {253 const q = toNumber(a) / toNumber(b)254 return q < 0255 ? fromNumberLossy(Math.ceil(q))256 : q > 0257 ? fromNumberLossy(Math.floor(q))258 : fromNumberLossy(q)259}260/**261 * @since 1.0.0262 */263export function rem(a: Int16, b: NonZero<Int16>): Int16 {264 return fromNumberLossy(toNumber(a) % toNumber(b))265}266/**267 * @since 1.0.0268 */269export function fromInt(n: Int): Option<Int16> {270 return pipe(Int.toNumber(n), option.chain(fromNumber))271}272/**273 * @since 1.0.0274 */275export function negate(a: Int16): Int16 {276 return sub(zero, a)277}278/**279 * @since 1.0.0280 */281export function pow(n: Int16, exp: Int16): Int16 {282 return fromNumberLossy(Math.pow(toNumber(n), toNumber(exp)))283}284/**285 * @since 1.0.0286 */287export function toInt(a: Int16): Int {288 return Int.of(a)289}290/**291 * @category Instances292 * @since 1.0.0293 */294const Eq: Eq<Int16> = {295 equals,296}297/**298 * @category Instances299 * @since 1.0.0300 */301export const Ord: Ord<Int16> = {302 equals,303 compare,304}305/**306 * @category Instances307 * @since 1.0.0308 */309export const Bounded: Bounded<Int16> = {310 equals,311 compare,312 bottom,313 top,314}315/**316 * @category Instances317 * @since 1.0.0318 */319export const Enum: Enum<Int16> = {320 equals,321 compare,322 next,323 prev,324}325/**326 * @category Instances327 * @since 1.0.0328 */329export const HasToRational: HasToRational<Int16> = {330 toRational,331}332/**333 * @category Instances334 * @since 1.0.0335 */336export const HasToInt: HasToInt<Int16> = {337 toInt,338}339/**340 * @category Instances341 * @since 1.0.0342 */343export const Integral: Integral<Int16> = {344 toRational,345 toInt,346 quot,347 rem,348}349/**350 * @category Instances351 * @since 1.0.0352 */353export const Numeric: Numeric<Int16> = {354 fromNumber,355 toNumber,356}357/**358 * @category Instances359 * @since 1.0.0360 */361export const Semiring: Semiring<Int16> = {362 add,363 mul,364 one,365 zero,366}367/**368 * @category Instances369 * @since 1.0.0370 */371export const Ring: Ring<Int16> = {372 add,373 mul,374 one,375 zero,376 sub,377}378/**379 * @category Instances380 * @since 1.0.0381 */382export const CommutativeRing: CommutativeRing<Int16> = Ring383/**384 * @category Instances385 * @since 1.0.0386 */387export const EuclideanRing: EuclideanRing<Int16> = {388 add,389 mul,390 one,391 zero,392 sub,393 degree,394 div,395 mod,396}397/**398 * @category Instances399 * @since 1.0.0400 */401export const Show: Show<Int16> = {402 show: (a) => JSON.stringify(toNumber(a)),403}404/**405 * @category Instances406 * @since 1.0.0407 */408export const HasPow: HasPow<Int16> = { pow }409/**410 * @since 1.0.0411 */412export const Int16: Bounded<Int16> &413 CommutativeRing<Int16> &414 Enum<Int16> &415 Eq<Int16> &416 EuclideanRing<Int16> &417 HasPow<Int16> &418 HasToInt<Int16> &419 HasToRational<Int16> &420 Integral<Int16> &421 Numeric<Int16> &422 Ord<Int16> &423 Ring<Int16> &424 Semiring<Int16> &425 Show<Int16> & {426 add: typeof add427 bottom: typeof bottom428 Bounded: typeof Bounded429 CommutativeRing: typeof CommutativeRing430 compare: typeof compare431 div: typeof div432 Enum: typeof Enum433 Eq: typeof Eq434 equals: typeof equals435 EuclideanRing: typeof EuclideanRing436 fromInt: typeof fromInt437 fromNumber: typeof fromNumber438 fromNumberLossy: typeof fromNumberLossy439 HasPow: typeof HasPow440 HasToInt: typeof HasToInt441 HasToRational: typeof HasToRational442 Integral: typeof Integral443 isTypeOf: typeof isTypeOf444 mod: typeof mod445 mul: typeof mul446 negate: typeof negate447 next: typeof next448 Numeric: typeof Numeric449 of: typeof of450 one: typeof one451 Ord: typeof Ord452 pow: typeof pow453 prev: typeof prev454 quot: typeof quot455 rem: typeof rem456 Ring: typeof Ring457 Semiring: typeof Semiring458 Show: typeof Show459 sub: typeof sub460 toInt: typeof toInt461 toNumber: typeof toNumber462 top: typeof top463 toRational: typeof toRational464 unsafeFromNumber: typeof unsafeFromNumber465 zero: typeof zero466 } = {467 add,468 bottom,469 Bounded,470 CommutativeRing,471 compare,472 degree,473 div,474 Enum,475 Eq,476 equals,477 EuclideanRing,478 fromInt,479 fromNumber,480 fromNumberLossy,481 HasPow,482 HasToInt,483 HasToRational,484 Integral,485 isTypeOf,486 mod,487 mul,488 negate,489 next,490 Numeric,491 of,492 one,493 Ord,494 pow,495 prev,496 quot,497 rem,498 Ring,499 Semiring,500 Show,501 show: Show.show,502 sub,503 toInt,504 toNumber,505 top,506 toRational,507 unsafeFromNumber,508 zero,...
toindex-byteoffset.js
Source:toindex-byteoffset.js
1// Copyright (C) 2016 the V8 project authors. All rights reserved.2// This code is governed by the BSD license found in the LICENSE file.3/*---4esid: sec-dataview.prototype.setint165es6id: 24.2.4.166description: >7 ToIndex conversions on byteOffset8info: |9 24.2.4.16 DataView.prototype.setInt16 ( byteOffset, value [ , littleEndian ] )10 1. Let v be the this value.11 2. If littleEndian is not present, let littleEndian be false.12 3. Return ? SetViewValue(v, byteOffset, littleEndian, "Int16", value).13 24.2.1.2 SetViewValue ( view, requestIndex, isLittleEndian, type, value )14 ...15 4. Let getIndex be ? ToIndex(requestIndex).16 ...17features: [DataView.prototype.getInt16]18---*/19var buffer = new ArrayBuffer(12);20var sample = new DataView(buffer, 0);21var obj1 = {22 valueOf: function() {23 return 3;24 }25};26var obj2 = {27 toString: function() {28 return 4;29 }30};31sample.setInt16(0, 0);32sample.setInt16(-0, 42);33assert.sameValue(sample.getInt16(0), 42, "-0");34sample.setInt16(3, 0);35sample.setInt16(obj1, 42);36assert.sameValue(sample.getInt16(3), 42, "object's valueOf");37sample.setInt16(4, 0);38sample.setInt16(obj2, 42);39assert.sameValue(sample.getInt16(4), 42, "object's toString");40sample.setInt16(0, 0);41sample.setInt16("", 42);42assert.sameValue(sample.getInt16(0), 42, "the Empty string");43sample.setInt16(0, 0);44sample.setInt16("0", 42);45assert.sameValue(sample.getInt16(0), 42, "string '0'");46sample.setInt16(2, 0);47sample.setInt16("2", 42);48assert.sameValue(sample.getInt16(2), 42, "string '2'");49sample.setInt16(1, 0);50sample.setInt16(true, 42);51assert.sameValue(sample.getInt16(1), 42, "true");52sample.setInt16(0, 0);53sample.setInt16(false, 42);54assert.sameValue(sample.getInt16(0), 42, "false");55sample.setInt16(0, 0);56sample.setInt16(NaN, 42);57assert.sameValue(sample.getInt16(0), 42, "NaN");58sample.setInt16(0, 0);59sample.setInt16(null, 42);60assert.sameValue(sample.getInt16(0), 42, "null");61sample.setInt16(0, 0);62sample.setInt16(0.1, 42);63assert.sameValue(sample.getInt16(0), 42, "0.1");64sample.setInt16(0, 0);65sample.setInt16(0.9, 42);66assert.sameValue(sample.getInt16(0), 42, "0.9");67sample.setInt16(1, 0);68sample.setInt16(1.1, 42);69assert.sameValue(sample.getInt16(1), 42, "1.1");70sample.setInt16(1, 0);71sample.setInt16(1.9, 42);72assert.sameValue(sample.getInt16(1), 42, "1.9");73sample.setInt16(0, 0);74sample.setInt16(-0.1, 42);75assert.sameValue(sample.getInt16(0), 42, "-0.1");76sample.setInt16(0, 0);77sample.setInt16(-0.99999, 42);78assert.sameValue(sample.getInt16(0), 42, "-0.99999");79sample.setInt16(0, 0);80sample.setInt16(undefined, 42);81assert.sameValue(sample.getInt16(0), 42, "undefined");82sample.setInt16(0, 7);83sample.setInt16();...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3}, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});
Using AI Code Generation
1const wptool = require('wptool');2wptool.int16(0, 0, 0, 0, 0, 0, 0, 0, (err, data) => {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9const wptool = require('wptool');10wptool.int16(0, 0, 0, 0, 0, 0, 0, 0, (err, data) => {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17- [Rajat Arya](
Using AI Code Generation
1var wptool = require('wptool');2var int16 = wptool.int16;3var int16 = wptool.int16;4var a = int16(0x1234);5var b = int16(0x5678);6console.log("a: 0x" + a.toString(16));7console.log("b: 0x" + b.toString(16));8console.log("a + b: 0x" + (a + b).toString(16));9console.log("a - b: 0x" + (a - b).toString(16));10console.log("a * b: 0x" + (a * b).toString(16));11console.log("a / b: 0x" + (a / b).toString(16));12console.log("a % b: 0x" + (a % b).toString(16));13console.log("a & b: 0x" + (a & b).toString(16));14console.log("a | b: 0x" + (a | b).toString(16));15console.log("a ^ b: 0x" + (a ^ b).toString(16));16console.log("a << 1: 0x" + (a << 1).toString(16));17console.log("a >> 1: 0x" + (a >> 1).toString(16));18console.log("a >>> 1: 0x" + (a >>> 1).toString(16));19console.log("a >>> 2: 0x" + (a >>> 2).toString(16));20console.log("a >>> 3: 0x" + (a >>> 3).toString(16));21console.log("a >>> 4: 0x" + (a >>> 4).toString(16));22console.log("a >>> 5: 0x" + (a >>> 5).toString(16));23console.log("a >>> 6: 0x" + (a >>> 6).toString(16));24console.log("a >>> 7: 0x" + (a >>> 7).toString(16));25console.log("a >>> 8: 0x" + (a >>> 8).toString(16));26console.log("a >>> 9: 0x" + (a >>>
Using AI Code Generation
1const wptool = require('wptool')2wptool.int16('0x00', '0x00').then((res) => {3 console.log(res)4})5wptool.int16(0x00, 0x00).then((res) => {6 console.log(res)7})8wptool.int16('0x00', 0x00).then((res) => {9 console.log(res)10})11wptool.int16(0x00, '0x00').then((res) => {12 console.log(res)13})14wptool.int16('0x00', '0x00').then((res) => {15 console.log(res)16})17wptool.int16('0x00', '0x00').then((res) => {18 console.log(res)19})20wptool.int16('0x00', '0x00').then((res) => {21 console.log(res)22})23wptool.int16('0x00', '0x00').then((res) => {24 console.log(res)25})26wptool.int16('0x00', '0x00').then((res) => {27 console.log(res)28})29wptool.int16('0x00', '0x00').then((res) => {30 console.log(res)31})32wptool.int16('0x00', '0x00').then((res) => {33 console.log(res)34})35- Github: [@aditya-mitra](
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!