Socket
Socket
Sign inDemoInstall

@hig/timestamp

Package Overview
Dependencies
Maintainers
6
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hig/timestamp - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

196

build/index.es.js

@@ -1,2 +0,2 @@

import React, { Component } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

@@ -34,136 +34,105 @@ import { css, cx } from 'emotion';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var pluralize = function pluralize(word, count) {
return count === 1 ? word : word + "s";
};
var Timestamp = function Timestamp(props) {
var getTimestampSequence = function getTimestampSequence(distance, ellapsedDescriptor) {
var timeDescriptors = props.timeDescriptors,
timestampSequence = props.timestampSequence,
wordSpace = props.wordSpace;
var Timestamp = function (_Component) {
_inherits(Timestamp, _Component);
var userTimestamp = void 0;
function Timestamp() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Timestamp);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
switch (timestampSequence) {
case "acb":
userTimestamp = wordSpace ? distance + " " + timeDescriptors.ago + " " + ellapsedDescriptor : "" + distance + timeDescriptors.ago + ellapsedDescriptor;
break;
case "bac":
userTimestamp = wordSpace ? ellapsedDescriptor + " " + distance + " " + timeDescriptors.ago : "" + ellapsedDescriptor + distance + timeDescriptors.ago;
break;
case "bca":
userTimestamp = wordSpace ? ellapsedDescriptor + " " + timeDescriptors.ago + " " + distance : "" + ellapsedDescriptor + timeDescriptors.ago + distance;
break;
case "cab":
userTimestamp = wordSpace ? timeDescriptors.ago + " " + distance + " " + ellapsedDescriptor : "" + timeDescriptors.ago + distance + ellapsedDescriptor;
break;
case "cba":
userTimestamp = wordSpace ? timeDescriptors.ago + " " + ellapsedDescriptor + " " + distance : "" + timeDescriptors.ago + ellapsedDescriptor + distance;
break;
default:
userTimestamp = wordSpace ? distance + " " + ellapsedDescriptor + " " + timeDescriptors.ago : "" + distance + ellapsedDescriptor + timeDescriptors.ago;
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Timestamp.__proto__ || Object.getPrototypeOf(Timestamp)).call.apply(_ref, [this].concat(args))), _this), _this.getTimestampSequence = function (distance, ellapsedDescriptor) {
var _this$props = _this.props,
timeDescriptors = _this$props.timeDescriptors,
timestampSequence = _this$props.timestampSequence,
wordSpace = _this$props.wordSpace;
return userTimestamp;
};
var userTimestamp = void 0;
var humanizeTimestamp = function humanizeTimestamp() {
var plural = props.plural,
timeDescriptors = props.timeDescriptors,
timestamp = props.timestamp;
switch (timestampSequence) {
case "acb":
userTimestamp = wordSpace ? distance + " " + timeDescriptors.ago + " " + ellapsedDescriptor : "" + distance + timeDescriptors.ago + ellapsedDescriptor;
break;
case "bac":
userTimestamp = wordSpace ? ellapsedDescriptor + " " + distance + " " + timeDescriptors.ago : "" + ellapsedDescriptor + distance + timeDescriptors.ago;
break;
case "bca":
userTimestamp = wordSpace ? ellapsedDescriptor + " " + timeDescriptors.ago + " " + distance : "" + ellapsedDescriptor + timeDescriptors.ago + distance;
break;
case "cab":
userTimestamp = wordSpace ? timeDescriptors.ago + " " + distance + " " + ellapsedDescriptor : "" + timeDescriptors.ago + distance + ellapsedDescriptor;
break;
case "cba":
userTimestamp = wordSpace ? timeDescriptors.ago + " " + ellapsedDescriptor + " " + distance : "" + timeDescriptors.ago + ellapsedDescriptor + distance;
break;
default:
userTimestamp = wordSpace ? distance + " " + ellapsedDescriptor + " " + timeDescriptors.ago : "" + distance + ellapsedDescriptor + timeDescriptors.ago;
}
var asSeconds = Date.parse(timestamp) / 1000; // TODO: handle future timestamps, or bad input?
var nowAsSeconds = new Date().valueOf() / 1000;
return userTimestamp;
}, _this.humanizeTimestamp = function () {
var _this$props2 = _this.props,
plural = _this$props2.plural,
timeDescriptors = _this$props2.timeDescriptors,
timestamp = _this$props2.timestamp;
var timeDifference = nowAsSeconds - asSeconds;
var distance = void 0;
var ellapsedDescriptor = void 0;
var asSeconds = Date.parse(timestamp) / 1000; // TODO: handle future timestamps, or bad input?
var nowAsSeconds = new Date().valueOf() / 1000;
if (timeDifference < 60) {
distance = Math.round(timeDifference);
ellapsedDescriptor = plural ? pluralize(timeDescriptors.second, distance) : timeDescriptors.second;
} else if (timeDifference < 60 * 60) {
// 1 hour
distance = Math.round(timeDifference / 60);
ellapsedDescriptor = plural ? pluralize(timeDescriptors.minute, distance) : timeDescriptors.minute;
} else if (timeDifference < 60 * 60 * 24) {
// 1 day
distance = Math.round(timeDifference / (60 * 60));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.hour, distance) : timeDescriptors.hour;
} else if (timeDifference < 60 * 60 * 24 * 7) {
// 1 week
distance = Math.round(timeDifference / (60 * 60 * 24));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.day, distance) : timeDescriptors.day;
} else if (timeDifference < 60 * 60 * 24 * (365 / 12)) {
// 1 month
distance = Math.round(timeDifference / (60 * 60 * 24 * 7));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.week, distance) : timeDescriptors.week;
} else if (timeDifference < 60 * 60 * 24 * 30 * 12) {
// # 1 year
distance = Math.round(timeDifference / (60 * 60 * 24 * (365 / 12)));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.month, distance) : timeDescriptors.month;
} else {
// More than 1 year
distance = Math.round(timeDifference / (60 * 60 * 24 * 365));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.year, distance) : timeDescriptors.year;
}
var timeDifference = nowAsSeconds - asSeconds;
var distance = void 0;
var ellapsedDescriptor = void 0;
return getTimestampSequence(distance, ellapsedDescriptor);
};
if (timeDifference < 60) {
distance = Math.round(timeDifference);
ellapsedDescriptor = plural ? pluralize(timeDescriptors.second, distance) : timeDescriptors.second;
} else if (timeDifference < 60 * 60) {
// 1 hour
distance = Math.round(timeDifference / 60);
ellapsedDescriptor = plural ? pluralize(timeDescriptors.minute, distance) : timeDescriptors.minute;
} else if (timeDifference < 60 * 60 * 24) {
// 1 day
distance = Math.round(timeDifference / (60 * 60));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.hour, distance) : timeDescriptors.hour;
} else if (timeDifference < 60 * 60 * 24 * 7) {
// 1 week
distance = Math.round(timeDifference / (60 * 60 * 24));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.day, distance) : timeDescriptors.day;
} else if (timeDifference < 60 * 60 * 24 * (365 / 12)) {
// 1 month
distance = Math.round(timeDifference / (60 * 60 * 24 * 7));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.week, distance) : timeDescriptors.week;
} else if (timeDifference < 60 * 60 * 24 * 30 * 12) {
// # 1 year
distance = Math.round(timeDifference / (60 * 60 * 24 * (365 / 12)));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.month, distance) : timeDescriptors.month;
} else {
// More than 1 year
distance = Math.round(timeDifference / (60 * 60 * 24 * 365));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.year, distance) : timeDescriptors.year;
}
return React.createElement(
ThemeContext.Consumer,
null,
function (_ref) {
var resolvedRoles = _ref.resolvedRoles,
metadata = _ref.metadata;
return _this.getTimestampSequence(distance, ellapsedDescriptor);
}, _temp), _possibleConstructorReturn(_this, _ret);
}
var customStylesheet = props.stylesheet,
otherProps = _objectWithoutProperties(props, ["stylesheet"]);
_createClass(Timestamp, [{
key: "render",
value: function render() {
var _this2 = this;
var className = otherProps.className;
var styles = stylesheet({ stylesheet: customStylesheet }, resolvedRoles, metadata.colorSchemeId);
return React.createElement(
ThemeContext.Consumer,
null,
function (_ref2) {
var resolvedRoles = _ref2.resolvedRoles,
metadata = _ref2.metadata;
var _props = _this2.props,
customStylesheet = _props.stylesheet,
otherProps = _objectWithoutProperties(_props, ["stylesheet"]);
var className = otherProps.className;
var styles = stylesheet({ stylesheet: customStylesheet }, resolvedRoles, metadata.colorSchemeId);
return React.createElement(
"div",
{ className: cx(css(styles.timestamp), className) },
_this2.humanizeTimestamp()
);
}
"div",
{ className: cx(css(styles.timestamp), className) },
humanizeTimestamp()
);
}
}]);
);
};
return Timestamp;
}(Component);
Timestamp.displayName = "Timestamp";

@@ -209,2 +178,3 @@ Timestamp.propTypes = {

};
Timestamp.defaultProps = {

@@ -211,0 +181,0 @@ plural: true,

@@ -7,4 +7,3 @@ 'use strict';

var React = require('react');
var React__default = _interopDefault(React);
var React = _interopDefault(require('react'));
var PropTypes = _interopDefault(require('prop-types'));

@@ -42,136 +41,105 @@ var emotion = require('emotion');

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var pluralize = function pluralize(word, count) {
return count === 1 ? word : word + "s";
};
var Timestamp = function Timestamp(props) {
var getTimestampSequence = function getTimestampSequence(distance, ellapsedDescriptor) {
var timeDescriptors = props.timeDescriptors,
timestampSequence = props.timestampSequence,
wordSpace = props.wordSpace;
var Timestamp = function (_Component) {
_inherits(Timestamp, _Component);
var userTimestamp = void 0;
function Timestamp() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Timestamp);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
switch (timestampSequence) {
case "acb":
userTimestamp = wordSpace ? distance + " " + timeDescriptors.ago + " " + ellapsedDescriptor : "" + distance + timeDescriptors.ago + ellapsedDescriptor;
break;
case "bac":
userTimestamp = wordSpace ? ellapsedDescriptor + " " + distance + " " + timeDescriptors.ago : "" + ellapsedDescriptor + distance + timeDescriptors.ago;
break;
case "bca":
userTimestamp = wordSpace ? ellapsedDescriptor + " " + timeDescriptors.ago + " " + distance : "" + ellapsedDescriptor + timeDescriptors.ago + distance;
break;
case "cab":
userTimestamp = wordSpace ? timeDescriptors.ago + " " + distance + " " + ellapsedDescriptor : "" + timeDescriptors.ago + distance + ellapsedDescriptor;
break;
case "cba":
userTimestamp = wordSpace ? timeDescriptors.ago + " " + ellapsedDescriptor + " " + distance : "" + timeDescriptors.ago + ellapsedDescriptor + distance;
break;
default:
userTimestamp = wordSpace ? distance + " " + ellapsedDescriptor + " " + timeDescriptors.ago : "" + distance + ellapsedDescriptor + timeDescriptors.ago;
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Timestamp.__proto__ || Object.getPrototypeOf(Timestamp)).call.apply(_ref, [this].concat(args))), _this), _this.getTimestampSequence = function (distance, ellapsedDescriptor) {
var _this$props = _this.props,
timeDescriptors = _this$props.timeDescriptors,
timestampSequence = _this$props.timestampSequence,
wordSpace = _this$props.wordSpace;
return userTimestamp;
};
var userTimestamp = void 0;
var humanizeTimestamp = function humanizeTimestamp() {
var plural = props.plural,
timeDescriptors = props.timeDescriptors,
timestamp = props.timestamp;
switch (timestampSequence) {
case "acb":
userTimestamp = wordSpace ? distance + " " + timeDescriptors.ago + " " + ellapsedDescriptor : "" + distance + timeDescriptors.ago + ellapsedDescriptor;
break;
case "bac":
userTimestamp = wordSpace ? ellapsedDescriptor + " " + distance + " " + timeDescriptors.ago : "" + ellapsedDescriptor + distance + timeDescriptors.ago;
break;
case "bca":
userTimestamp = wordSpace ? ellapsedDescriptor + " " + timeDescriptors.ago + " " + distance : "" + ellapsedDescriptor + timeDescriptors.ago + distance;
break;
case "cab":
userTimestamp = wordSpace ? timeDescriptors.ago + " " + distance + " " + ellapsedDescriptor : "" + timeDescriptors.ago + distance + ellapsedDescriptor;
break;
case "cba":
userTimestamp = wordSpace ? timeDescriptors.ago + " " + ellapsedDescriptor + " " + distance : "" + timeDescriptors.ago + ellapsedDescriptor + distance;
break;
default:
userTimestamp = wordSpace ? distance + " " + ellapsedDescriptor + " " + timeDescriptors.ago : "" + distance + ellapsedDescriptor + timeDescriptors.ago;
}
var asSeconds = Date.parse(timestamp) / 1000; // TODO: handle future timestamps, or bad input?
var nowAsSeconds = new Date().valueOf() / 1000;
return userTimestamp;
}, _this.humanizeTimestamp = function () {
var _this$props2 = _this.props,
plural = _this$props2.plural,
timeDescriptors = _this$props2.timeDescriptors,
timestamp = _this$props2.timestamp;
var timeDifference = nowAsSeconds - asSeconds;
var distance = void 0;
var ellapsedDescriptor = void 0;
var asSeconds = Date.parse(timestamp) / 1000; // TODO: handle future timestamps, or bad input?
var nowAsSeconds = new Date().valueOf() / 1000;
if (timeDifference < 60) {
distance = Math.round(timeDifference);
ellapsedDescriptor = plural ? pluralize(timeDescriptors.second, distance) : timeDescriptors.second;
} else if (timeDifference < 60 * 60) {
// 1 hour
distance = Math.round(timeDifference / 60);
ellapsedDescriptor = plural ? pluralize(timeDescriptors.minute, distance) : timeDescriptors.minute;
} else if (timeDifference < 60 * 60 * 24) {
// 1 day
distance = Math.round(timeDifference / (60 * 60));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.hour, distance) : timeDescriptors.hour;
} else if (timeDifference < 60 * 60 * 24 * 7) {
// 1 week
distance = Math.round(timeDifference / (60 * 60 * 24));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.day, distance) : timeDescriptors.day;
} else if (timeDifference < 60 * 60 * 24 * (365 / 12)) {
// 1 month
distance = Math.round(timeDifference / (60 * 60 * 24 * 7));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.week, distance) : timeDescriptors.week;
} else if (timeDifference < 60 * 60 * 24 * 30 * 12) {
// # 1 year
distance = Math.round(timeDifference / (60 * 60 * 24 * (365 / 12)));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.month, distance) : timeDescriptors.month;
} else {
// More than 1 year
distance = Math.round(timeDifference / (60 * 60 * 24 * 365));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.year, distance) : timeDescriptors.year;
}
var timeDifference = nowAsSeconds - asSeconds;
var distance = void 0;
var ellapsedDescriptor = void 0;
return getTimestampSequence(distance, ellapsedDescriptor);
};
if (timeDifference < 60) {
distance = Math.round(timeDifference);
ellapsedDescriptor = plural ? pluralize(timeDescriptors.second, distance) : timeDescriptors.second;
} else if (timeDifference < 60 * 60) {
// 1 hour
distance = Math.round(timeDifference / 60);
ellapsedDescriptor = plural ? pluralize(timeDescriptors.minute, distance) : timeDescriptors.minute;
} else if (timeDifference < 60 * 60 * 24) {
// 1 day
distance = Math.round(timeDifference / (60 * 60));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.hour, distance) : timeDescriptors.hour;
} else if (timeDifference < 60 * 60 * 24 * 7) {
// 1 week
distance = Math.round(timeDifference / (60 * 60 * 24));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.day, distance) : timeDescriptors.day;
} else if (timeDifference < 60 * 60 * 24 * (365 / 12)) {
// 1 month
distance = Math.round(timeDifference / (60 * 60 * 24 * 7));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.week, distance) : timeDescriptors.week;
} else if (timeDifference < 60 * 60 * 24 * 30 * 12) {
// # 1 year
distance = Math.round(timeDifference / (60 * 60 * 24 * (365 / 12)));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.month, distance) : timeDescriptors.month;
} else {
// More than 1 year
distance = Math.round(timeDifference / (60 * 60 * 24 * 365));
ellapsedDescriptor = plural ? pluralize(timeDescriptors.year, distance) : timeDescriptors.year;
}
return React.createElement(
ThemeContext.Consumer,
null,
function (_ref) {
var resolvedRoles = _ref.resolvedRoles,
metadata = _ref.metadata;
return _this.getTimestampSequence(distance, ellapsedDescriptor);
}, _temp), _possibleConstructorReturn(_this, _ret);
}
var customStylesheet = props.stylesheet,
otherProps = _objectWithoutProperties(props, ["stylesheet"]);
_createClass(Timestamp, [{
key: "render",
value: function render() {
var _this2 = this;
var className = otherProps.className;
return React__default.createElement(
ThemeContext.Consumer,
null,
function (_ref2) {
var resolvedRoles = _ref2.resolvedRoles,
metadata = _ref2.metadata;
var _props = _this2.props,
customStylesheet = _props.stylesheet,
otherProps = _objectWithoutProperties(_props, ["stylesheet"]);
var className = otherProps.className;
var styles = stylesheet({ stylesheet: customStylesheet }, resolvedRoles, metadata.colorSchemeId);
return React__default.createElement(
"div",
{ className: emotion.cx(emotion.css(styles.timestamp), className) },
_this2.humanizeTimestamp()
);
}
var styles = stylesheet({ stylesheet: customStylesheet }, resolvedRoles, metadata.colorSchemeId);
return React.createElement(
"div",
{ className: emotion.cx(emotion.css(styles.timestamp), className) },
humanizeTimestamp()
);
}
}]);
);
};
return Timestamp;
}(React.Component);
Timestamp.displayName = "Timestamp";

@@ -217,2 +185,3 @@ Timestamp.propTypes = {

};
Timestamp.defaultProps = {

@@ -219,0 +188,0 @@ plural: true,

@@ -0,1 +1,8 @@

# [@hig/timestamp-v1.3.1](https://github.com/Autodesk/hig/compare/@hig/timestamp@1.3.0...@hig/timestamp@1.3.1) (2022-01-12)
### Bug Fixes
* react v. in peerDependencies instead of dependencies ([4701332](https://github.com/Autodesk/hig/commit/4701332))
# [@hig/timestamp-v1.3.0](https://github.com/Autodesk/hig/compare/@hig/timestamp@1.2.0...@hig/timestamp@1.3.0) (2020-10-15)

@@ -2,0 +9,0 @@

{
"name": "@hig/timestamp",
"version": "1.3.0",
"version": "1.3.1",
"description": "HIG Timestamp",

@@ -33,5 +33,5 @@ "author": "Autodesk Inc.",

"peerDependencies": {
"@hig/theme-context": "^3.0.1",
"@hig/theme-data": "^2.18.0",
"react": "^15.4.1 || ^16.3.2"
"@hig/theme-context": "^3.0.2",
"@hig/theme-data": "^2.22.0",
"react": "^17.0.0"
},

@@ -38,0 +38,0 @@ "scripts": {

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