Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cucumber/messages

Package Overview
Dependencies
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cucumber/messages - npm Package Compare versions

Comparing version 11.1.0 to 11.1.1

1

dist/src/TimeConversion.d.ts

@@ -6,1 +6,2 @@ import { messages } from './index';

export declare function durationToMilliseconds(duration: messages.IDuration): number;
export declare function addDurations(durationA: messages.IDuration, durationB: messages.IDuration): messages.Duration;

28

dist/src/TimeConversion.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require("./index");
var MILLISECONDS_PER_SECOND = 1000;
var NANOSECONDS_PER_MILLISECOND = 1000000;
var MILLISECONDS_PER_SECOND = 1e3;
var NANOSECONDS_PER_MILLISECOND = 1e6;
var NANOSECONDS_PER_SECOND = 1e9;
function millisecondsSinceEpochToTimestamp(millisecondsSinceEpoch) {

@@ -24,2 +25,15 @@ return new index_1.messages.Timestamp(toSecondsAndNanos(millisecondsSinceEpoch));

exports.durationToMilliseconds = durationToMilliseconds;
function addDurations(durationA, durationB) {
var seconds = toNumber(durationA.seconds) + toNumber(durationB.seconds);
var nanos = durationA.nanos + durationB.nanos;
if (nanos >= NANOSECONDS_PER_SECOND) {
seconds += 1;
nanos -= NANOSECONDS_PER_SECOND;
}
return new index_1.messages.Duration({ seconds: seconds, nanos: nanos });
}
exports.addDurations = addDurations;
function toNumber(x) {
return typeof x === 'number' ? x : x.toNumber();
}
function toSecondsAndNanos(milliseconds) {

@@ -31,11 +45,3 @@ var seconds = Math.floor(milliseconds / MILLISECONDS_PER_SECOND);

function toMillis(seconds, nanos) {
var secondMillis;
if (typeof seconds === 'number') {
secondMillis = seconds * MILLISECONDS_PER_SECOND;
}
else {
secondMillis = seconds
.multiply(MILLISECONDS_PER_SECOND)
.toNumber();
}
var secondMillis = toNumber(seconds) * MILLISECONDS_PER_SECOND;
var nanoMillis = nanos / NANOSECONDS_PER_MILLISECOND;

@@ -42,0 +48,0 @@ return secondMillis + nanoMillis;

@@ -8,2 +8,3 @@ "use strict";

var src_1 = require("../src");
var TimeConversion_1 = require("../src/TimeConversion");
var durationToMilliseconds = src_1.TimeConversion.durationToMilliseconds, millisecondsSinceEpochToTimestamp = src_1.TimeConversion.millisecondsSinceEpochToTimestamp, millisecondsToDuration = src_1.TimeConversion.millisecondsToDuration, timestampToMillisecondsSinceEpoch = src_1.TimeConversion.timestampToMillisecondsSinceEpoch;

@@ -29,3 +30,21 @@ describe('TimeConversion', function () {

});
it('adds durations (nanos only)', function () {
var durationA = millisecondsToDuration(100);
var durationB = millisecondsToDuration(200);
var sumDuration = TimeConversion_1.addDurations(durationA, durationB);
assert_1.default.deepStrictEqual(sumDuration, new src_1.messages.Duration({ seconds: 0, nanos: 3e8 }));
});
it('adds durations (nanos only)', function () {
var durationA = millisecondsToDuration(1000);
var durationB = millisecondsToDuration(2000);
var sumDuration = TimeConversion_1.addDurations(durationA, durationB);
assert_1.default.deepStrictEqual(sumDuration, new src_1.messages.Duration({ seconds: 3, nanos: 0 }));
});
it('adds durations (seconds and nanos)', function () {
var durationA = millisecondsToDuration(1500);
var durationB = millisecondsToDuration(1600);
var sumDuration = TimeConversion_1.addDurations(durationA, durationB);
assert_1.default.deepStrictEqual(sumDuration, new src_1.messages.Duration({ seconds: 3, nanos: 1e8 }));
});
});
//# sourceMappingURL=TimeConversionTest.js.map
{
"name": "@cucumber/messages",
"version": "11.1.0",
"version": "11.1.1",
"description": "Protocol Buffer messages for Cucumber's inter-process communication",

@@ -30,3 +30,3 @@ "main": "dist/src/index.js",

"@types/mocha": "^7.0.2",
"@types/node": "^13.9.6",
"@types/node": "^13.9.7",
"@typescript-eslint/eslint-plugin": "^2.26.0",

@@ -33,0 +33,0 @@ "@typescript-eslint/parser": "^2.26.0",

import { messages } from './index'
const MILLISECONDS_PER_SECOND = 1000
const NANOSECONDS_PER_MILLISECOND = 1000000
const MILLISECONDS_PER_SECOND = 1e3
const NANOSECONDS_PER_MILLISECOND = 1e6
const NANOSECONDS_PER_SECOND = 1e9

@@ -30,2 +31,19 @@ export function millisecondsSinceEpochToTimestamp(

export function addDurations(
durationA: messages.IDuration,
durationB: messages.IDuration
) {
let seconds = toNumber(durationA.seconds) + toNumber(durationB.seconds)
let nanos = durationA.nanos + durationB.nanos
if (nanos >= NANOSECONDS_PER_SECOND) {
seconds += 1
nanos -= NANOSECONDS_PER_SECOND
}
return new messages.Duration({ seconds, nanos })
}
function toNumber(x: number | Long): number {
return typeof x === 'number' ? x : x.toNumber()
}
function toSecondsAndNanos(milliseconds: number) {

@@ -40,12 +58,5 @@ const seconds = Math.floor(milliseconds / MILLISECONDS_PER_SECOND)

function toMillis(seconds: number | Long, nanos: number) {
let secondMillis: number
if (typeof seconds === 'number') {
secondMillis = (seconds as number) * MILLISECONDS_PER_SECOND
} else {
secondMillis = (seconds as Long)
.multiply(MILLISECONDS_PER_SECOND)
.toNumber()
}
const secondMillis = toNumber(seconds) * MILLISECONDS_PER_SECOND
const nanoMillis = nanos / NANOSECONDS_PER_MILLISECOND
return secondMillis + nanoMillis
}
import assert from 'assert'
import { TimeConversion } from '../src'
import { TimeConversion, messages } from '../src'
import { addDurations } from '../src/TimeConversion'

@@ -35,2 +36,35 @@ const {

})
it('adds durations (nanos only)', () => {
const durationA = millisecondsToDuration(100)
const durationB = millisecondsToDuration(200)
const sumDuration = addDurations(durationA, durationB)
assert.deepStrictEqual(
sumDuration,
new messages.Duration({ seconds: 0, nanos: 3e8 })
)
})
it('adds durations (nanos only)', () => {
const durationA = millisecondsToDuration(1000)
const durationB = millisecondsToDuration(2000)
const sumDuration = addDurations(durationA, durationB)
assert.deepStrictEqual(
sumDuration,
new messages.Duration({ seconds: 3, nanos: 0 })
)
})
it('adds durations (seconds and nanos)', () => {
const durationA = millisecondsToDuration(1500)
const durationB = millisecondsToDuration(1600)
const sumDuration = addDurations(durationA, durationB)
assert.deepStrictEqual(
sumDuration,
new messages.Duration({ seconds: 3, nanos: 1e8 })
)
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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