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

@boulevard/duration-select

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@boulevard/duration-select - npm Package Compare versions

Comparing version 1.0.0-alpha.13 to 1.0.0-alpha.14

6

package.json
{
"name": "@boulevard/duration-select",
"version": "1.0.0-alpha.13",
"version": "1.0.0-alpha.14",
"description": "A component for intelligently selecting durations.",

@@ -10,3 +10,3 @@ "main": "index.ts",

"peerDependencies": {
"@boulevard/cdk": "^1.0.0-alpha.4",
"@boulevard/cdk": "^1.0.0-alpha.6",
"@boulevard/material": "^1.0.0-alpha.3",

@@ -18,3 +18,3 @@ "lit-element": "^2.0.1",

"devDependencies": {
"@boulevard/cdk": "^1.0.0-alpha.4",
"@boulevard/cdk": "^1.0.0-alpha.6",
"@boulevard/material": "^1.0.0-alpha.3",

@@ -21,0 +21,0 @@ "lit-element": "^2.0.1",

@@ -1,5 +0,5 @@

import { css, customElement, eventOptions, html, LitElement, property, PropertyValues, query } from 'lit-element';
import { customElement, eventOptions, html, LitElement, property, PropertyValues, query } from 'lit-element';
import { Shadowless } from '@boulevard/cdk';
import '@boulevard/material';
import { bind } from '@boulevard/cdk';
import { DurationSelectHelpers, DurationSelectInterface } from './duration-select.helpers';

@@ -91,2 +91,22 @@

connectedCallback() {
super.connectedCallback();
if ('ontouchstart' in document) {
document.addEventListener('touchstart', this._touchstart);
}
}
disconnectedCallback() {
super.disconnectedCallback();
if ('ontouchstart' in document) {
document.removeEventListener('touchstart', this._touchstart);
}
}
@bind
private _touchstart(e: TouchEvent): void {
e.target !== this._input && this._updateDurationSelect(this._readout, e);
}
/**

@@ -93,0 +113,0 @@ * Combine preventDefault() and stopPropagation() to reduce code repetition

@@ -29,3 +29,3 @@ export interface DurationSelectInterface {

? Math.floor(duration / 60)
: maxDurationHours;
: 0;

@@ -40,3 +40,3 @@ // Default minutes to the maximum number of minutes in an hours minus the rounding inteval

let roundedValue: number = duration >= maxDuration
? maxDuration
? minDuration
: Math.ceil(duration / roundToIncrement) * roundToIncrement;

@@ -96,3 +96,3 @@

const hasHours: boolean = this._hourShortcuts.some((item: string) => noSpacesReadoutArray.includes(item));
let durationInMinutes: number = defaultDuration || maxDuration;
let durationInMinutes: number = defaultDuration || minDuration;

@@ -149,46 +149,2 @@ // Ignore formatting if the input field is empty

}
/**
* Round minutes up to the nearest increment and convert into an object that has the
* model (string ex: 1h 5m) and the value.
* @param value
*/
private static _formatFromMinutes(value: number, minDuration: number, maxDuration: number,
roundToIncrement: number, incrementDirection?: string): DurationSelectInterface {
// Add or subtract roundToIncrement when using arrow up and down keys
if (incrementDirection === 'nextIncrement' && value <= maxDuration - roundToIncrement) {
value = value + roundToIncrement;
} else if (incrementDirection === 'previousIncrement' && value >= minDuration + roundToIncrement) {
value = value - roundToIncrement;
}
let maxDurationHours: number = Math.floor(maxDuration / 60);
let hours: number = value / 60 <= maxDurationHours
? Math.floor(value / 60)
: maxDurationHours;
// Default minutes to the maximum number of minutes in an hours minus the rounding inteval
// This will lead to a super high number being formatted as the max duration in hours and mins
let minutes: number = hours >= maxDurationHours
? (60 - roundToIncrement)
: roundToIncrement;
let roundedValue: number = maxDuration;
if (value >= minDuration && value <= maxDuration) {
// Round remaining minutes up to interval unless that interval is 60, then set to 55
minutes = value % 60 < (60 - roundToIncrement)
? Math.ceil((value % 60) / roundToIncrement) * roundToIncrement
: (60 - roundToIncrement);
// Round the full value passed in, represents the total hours and minutes in minutes
roundedValue = Math.ceil(value / roundToIncrement) * roundToIncrement;
}
return {
readout: `${hours > 0 ? hours + 'h ' : ''}${minutes}m`,
value: roundedValue
};
}
}
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