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

@encodable/format

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@encodable/format - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [0.4.2](https://github.com/apache-superset/encodable/compare/@encodable/format@0.4.1...@encodable/format@0.4.2) (2020-08-13)
**Note:** Version bump only for package @encodable/format
## [0.4.1](https://github.com/apache-superset/encodable/compare/@encodable/format@0.4.0...@encodable/format@0.4.1) (2020-08-03)

@@ -8,0 +16,0 @@

16

esm/FormatterRegistry.js

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

"use strict";
exports.__esModule = true;
exports.default = void 0;
var _registry = require("@encodable/registry");
class FormatterRegistry extends _registry.SyncRegistry {
import { SyncRegistry, OverwritePolicy } from '@encodable/registry';
export default class FormatterRegistry extends SyncRegistry {
constructor({
overwritePolicy = _registry.OverwritePolicy.WARN,
overwritePolicy = OverwritePolicy.WARN,
...rest

@@ -51,4 +45,2 @@ }) {

}
exports.default = FormatterRegistry;
}

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

"use strict";
export * from './number';
export * from './time';
export * from './timeRange'; // Types
exports.__esModule = true;
var _exportNames = {
fallbackFormatter: true
};
exports.fallbackFormatter = void 0;
export * from './types'; // Utils
var _number = require("./number");
Object.keys(_number).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
exports[key] = _number[key];
});
var _time = require("./time");
Object.keys(_time).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
exports[key] = _time[key];
});
var _timeRange = require("./timeRange");
Object.keys(_timeRange).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
exports[key] = _timeRange[key];
});
var _types = require("./types");
Object.keys(_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
exports[key] = _types[key];
});
var _fallbackFormatter = _interopRequireDefault(require("./utils/fallbackFormatter"));
exports.fallbackFormatter = _fallbackFormatter.default;
var _prefix = require("./utils/prefix");
Object.keys(_prefix).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
exports[key] = _prefix[key];
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
export { default as fallbackFormatter } from './utils/fallbackFormatter';
export * from './utils/prefix';

@@ -1,6 +0,1 @@

"use strict";
exports.__esModule = true;
exports.default = createNumberFormatter;
function cleanAndFormat(value, formatFunc) {

@@ -22,3 +17,3 @@ if (value === null || value === undefined || Number.isNaN(value)) {

function createNumberFormatter(formatFunc, metadata) {
export default function createNumberFormatter(formatFunc, metadata) {
const format = value => cleanAndFormat(value, formatFunc);

@@ -25,0 +20,0 @@

@@ -1,13 +0,4 @@

"use strict";
exports.__esModule = true;
exports.default = createD3NumberFormatter;
var _d3Format = require("d3-format");
var _createNumberFormatter = _interopRequireDefault(require("../createNumberFormatter"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createD3NumberFormatter({
import { format as d3Format, formatLocale } from 'd3-format';
import createNumberFormatter from '../createNumberFormatter';
export default function createD3NumberFormatter({
format,

@@ -23,3 +14,3 @@ locale,

try {
formatFunc = typeof locale === 'undefined' ? (0, _d3Format.format)(format) : (0, _d3Format.formatLocale)(locale).format(format);
formatFunc = typeof locale === 'undefined' ? d3Format(format) : formatLocale(locale).format(format);
} catch (error) {

@@ -31,3 +22,3 @@ formatFunc = value => value + " (Invalid format: " + format + ")";

return (0, _createNumberFormatter.default)(formatFunc, {
return createNumberFormatter(formatFunc, {
id: id != null ? id : format,

@@ -34,0 +25,0 @@ label,

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

"use strict";
import { format as d3Format } from 'd3-format';
import NumberFormats from '../NumberFormats';
import createNumberFormatter from '../createNumberFormatter';
const siFormatter = d3Format(".3~s");
const float2PointFormatter = d3Format(".2~f");
const float4PointFormatter = d3Format(".4~f");
exports.__esModule = true;
exports.default = createSmartNumberFormatter;
var _d3Format = require("d3-format");
var _NumberFormats = _interopRequireDefault(require("../NumberFormats"));
var _createNumberFormatter = _interopRequireDefault(require("../createNumberFormatter"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const siFormatter = (0, _d3Format.format)(".3~s");
const float2PointFormatter = (0, _d3Format.format)(".2~f");
const float4PointFormatter = (0, _d3Format.format)(".4~f");
function formatValue(value) {

@@ -50,3 +40,3 @@ if (value === 0) {

function createSmartNumberFormatter({
export default function createSmartNumberFormatter({
signed = false,

@@ -58,4 +48,4 @@ id,

const getSign = signed ? ADD_PLUS : BLANK;
return (0, _createNumberFormatter.default)(value => "" + getSign(value) + formatValue(value), {
id: (id != null ? id : signed) ? _NumberFormats.default.signed.SMART_NUMBER : _NumberFormats.default.SMART_NUMBER,
return createNumberFormatter(value => "" + getSign(value) + formatValue(value), {
id: (id != null ? id : signed) ? NumberFormats.signed.SMART_NUMBER : NumberFormats.SMART_NUMBER,
label: label != null ? label : 'Adaptive formatter',

@@ -62,0 +52,0 @@ description

@@ -1,47 +0,17 @@

"use strict";
exports.__esModule = true;
exports.getNumberFormatter = getNumberFormatter;
exports.formatNumber = formatNumber;
exports.createSmartNumberFormatter = exports.createD3NumberFormatter = exports.previewNumber = exports.createNumberFormatter = exports.NumberFormats = exports.getNumberFormatterRegistry = void 0;
var _registry = require("@encodable/registry");
var _NumberFormatterRegistry = _interopRequireDefault(require("./NumberFormatterRegistry"));
exports.NumberFormatterRegistry = _NumberFormatterRegistry.default;
var _NumberFormats = _interopRequireDefault(require("./NumberFormats"));
exports.NumberFormats = _NumberFormats.default;
var _createNumberFormatter = _interopRequireDefault(require("./createNumberFormatter"));
exports.createNumberFormatter = _createNumberFormatter.default;
var _previewNumber = _interopRequireDefault(require("./previewNumber"));
exports.previewNumber = _previewNumber.default;
var _createD3NumberFormatter = _interopRequireDefault(require("./factories/createD3NumberFormatter"));
exports.createD3NumberFormatter = _createD3NumberFormatter.default;
var _createSmartNumberFormatter = _interopRequireDefault(require("./factories/createSmartNumberFormatter"));
exports.createSmartNumberFormatter = _createSmartNumberFormatter.default;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const getNumberFormatterRegistry = (0, _registry.makeSingleton)(() => new _NumberFormatterRegistry.default({
import { makeSingleton } from '@encodable/registry';
import NumberFormatterRegistry from './NumberFormatterRegistry';
export const getNumberFormatterRegistry = makeSingleton(() => new NumberFormatterRegistry({
globalId: '@encodable/format:NumberFormatterRegistry'
}));
exports.getNumberFormatterRegistry = getNumberFormatterRegistry;
function getNumberFormatter(format) {
export function getNumberFormatter(format) {
return getNumberFormatterRegistry().get(format);
}
function formatNumber(format, value) {
export function formatNumber(format, value) {
return getNumberFormatterRegistry().format(format, value);
}
}
export { NumberFormatterRegistry };
export { default as NumberFormats } from './NumberFormats';
export { default as createNumberFormatter } from './createNumberFormatter';
export { default as previewNumber } from './previewNumber';
export { default as createD3NumberFormatter } from './factories/createD3NumberFormatter';
export { default as createSmartNumberFormatter } from './factories/createSmartNumberFormatter';

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

"use strict";
exports.__esModule = true;
exports.default = void 0;
var _prefix = require("../utils/prefix");
import { addSign } from '../utils/prefix';
const unsigned = {

@@ -28,8 +22,7 @@ CURRENCY: '$,.2f',

// eslint-disable-next-line no-param-reassign
prev[key] = (0, _prefix.addSign)(value);
prev[key] = addSign(value);
return prev;
}, {});
var _default = { ...unsigned,
export default { ...unsigned,
signed
};
exports.default = _default;
};

@@ -1,17 +0,6 @@

"use strict";
exports.__esModule = true;
exports.default = void 0;
var _createD3NumberFormatter = _interopRequireDefault(require("./factories/createD3NumberFormatter"));
var _createSmartNumberFormatter = _interopRequireDefault(require("./factories/createSmartNumberFormatter"));
var _NumberFormats = _interopRequireDefault(require("./NumberFormats"));
var _FormatterRegistry = _interopRequireDefault(require("../FormatterRegistry"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class NumberFormatterRegistry extends _FormatterRegistry.default {
import createD3NumberFormatter from './factories/createD3NumberFormatter';
import createSmartNumberFormatter from './factories/createSmartNumberFormatter';
import Formats from './NumberFormats';
import FormatterRegistry from '../FormatterRegistry';
export default class NumberFormatterRegistry extends FormatterRegistry {
constructor({

@@ -25,7 +14,7 @@ name = 'NumberFormatter',

});
this.registerValue(_NumberFormats.default.SMART_NUMBER, (0, _createSmartNumberFormatter.default)());
this.registerValue(_NumberFormats.default.signed.SMART_NUMBER, (0, _createSmartNumberFormatter.default)({
this.registerValue(Formats.SMART_NUMBER, createSmartNumberFormatter());
this.registerValue(Formats.signed.SMART_NUMBER, createSmartNumberFormatter({
signed: true
}));
this.setDefaultKey(_NumberFormats.default.SMART_NUMBER);
this.setDefaultKey(Formats.SMART_NUMBER);
} // eslint-disable-next-line class-methods-use-this

@@ -35,3 +24,3 @@

createFormatter(format) {
return (0, _createD3NumberFormatter.default)({
return createD3NumberFormatter({
format

@@ -41,4 +30,2 @@ });

}
exports.default = NumberFormatterRegistry;
}

@@ -1,11 +0,4 @@

"use strict";
exports.__esModule = true;
exports.default = previewNumber;
exports.PREVIEW_VALUE = void 0;
const PREVIEW_VALUE = 12345.432;
exports.PREVIEW_VALUE = PREVIEW_VALUE;
function previewNumber(format, value = PREVIEW_VALUE) {
export const PREVIEW_VALUE = 12345.432;
export default function previewNumber(format, value = PREVIEW_VALUE) {
return value + " => " + format(value);
}

@@ -1,6 +0,1 @@

"use strict";
exports.__esModule = true;
exports.default = createTimeFormatter;
function cleanAndFormat(value, formatFunc) {

@@ -14,3 +9,3 @@ if (value === null || value === undefined) {

function createTimeFormatter(formatFunc, metadata) {
export default function createTimeFormatter(formatFunc, metadata) {
const format = value => cleanAndFormat(value, formatFunc);

@@ -17,0 +12,0 @@

@@ -1,17 +0,6 @@

"use strict";
exports.__esModule = true;
exports.default = createD3TimeFormatter;
var _d3TimeFormat = require("d3-time-format");
var _TimeFormats = require("../TimeFormats");
var _createTimeFormatter = _interopRequireDefault(require("../createTimeFormatter"));
var _prefix = require("../../utils/prefix");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createD3TimeFormatter({
import { utcFormat, timeFormat, timeFormatLocale } from 'd3-time-format';
import { LOCAL_TIME_PREFIX } from '../TimeFormats';
import createTimeFormatter from '../createTimeFormatter';
import { addPrefix } from '../../utils/prefix';
export default function createD3TimeFormatter({
format,

@@ -27,11 +16,11 @@ locale,

if (typeof locale === 'undefined') {
const factory = useLocalTime ? _d3TimeFormat.timeFormat : _d3TimeFormat.utcFormat;
const factory = useLocalTime ? timeFormat : utcFormat;
formatFunc = factory(format);
} else {
const localeObject = (0, _d3TimeFormat.timeFormatLocale)(locale);
const localeObject = timeFormatLocale(locale);
formatFunc = useLocalTime ? localeObject.format(format) : localeObject.utcFormat(format);
}
return (0, _createTimeFormatter.default)(formatFunc, {
id: id != null ? id : useLocalTime ? (0, _prefix.addPrefix)(_TimeFormats.LOCAL_TIME_PREFIX, format) : format,
return createTimeFormatter(formatFunc, {
id: id != null ? id : useLocalTime ? addPrefix(LOCAL_TIME_PREFIX, format) : format,
label,

@@ -38,0 +27,0 @@ description,

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

"use strict";
exports.__esModule = true;
exports.default = createMultiTimeFormatter;
var _d3TimeFormat = require("d3-time-format");
var _d3Time = require("../utils/d3Time");
var _createTimeFormatter = _interopRequireDefault(require("../createTimeFormatter"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createMultiTimeFormatter({
import { utcFormat, timeFormat } from 'd3-time-format';
import { utcUtils, localTimeUtils } from '../utils/d3Time';
import createTimeFormatter from '../createTimeFormatter';
export default function createMultiTimeFormatter({
id,

@@ -31,3 +21,3 @@ label,

} = formats;
const format = useLocalTime ? _d3TimeFormat.timeFormat : _d3TimeFormat.utcFormat;
const format = useLocalTime ? timeFormat : utcFormat;
const formatMillisecond = format(millisecond);

@@ -49,3 +39,3 @@ const formatSecond = format(second);

isNotFirstMonth
} = useLocalTime ? _d3Time.localTimeUtils : _d3Time.utcUtils;
} = useLocalTime ? localTimeUtils : utcUtils;

@@ -80,3 +70,3 @@ function multiFormatFunc(date) {

return (0, _createTimeFormatter.default)(date => multiFormatFunc(date)(date), {
return createTimeFormatter(date => multiFormatFunc(date)(date), {
id,

@@ -83,0 +73,0 @@ label,

@@ -1,11 +0,3 @@

"use strict";
exports.__esModule = true;
exports.default = void 0;
var _createMultiTimeFormatter = _interopRequireDefault(require("../factories/createMultiTimeFormatter"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const smartDateFormatter = (0, _createMultiTimeFormatter.default)({
import createMultiTimeFormatter from '../factories/createMultiTimeFormatter';
const smartDateFormatter = createMultiTimeFormatter({
id: 'smart_date',

@@ -24,3 +16,2 @@ label: 'Adaptative Formatting',

});
var _default = smartDateFormatter;
exports.default = _default;
export default smartDateFormatter;

@@ -1,11 +0,3 @@

"use strict";
exports.__esModule = true;
exports.default = void 0;
var _createMultiTimeFormatter = _interopRequireDefault(require("../factories/createMultiTimeFormatter"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const smartDateFormatter = (0, _createMultiTimeFormatter.default)({
import createMultiTimeFormatter from '../factories/createMultiTimeFormatter';
const smartDateFormatter = createMultiTimeFormatter({
id: 'smart_date_verbose',

@@ -24,3 +16,2 @@ label: 'Verbose Adaptative Formatting',

});
var _default = smartDateFormatter;
exports.default = _default;
export default smartDateFormatter;

@@ -1,60 +0,19 @@

"use strict";
exports.__esModule = true;
exports.getTimeFormatter = getTimeFormatter;
exports.formatTime = formatTime;
exports.LOCAL_TIME_PREFIX = exports.smartDateVerboseFormatter = exports.smartDateFormatter = exports.createMultiTimeFormatter = exports.createD3TimeFormatter = exports.previewTime = exports.createTimeFormatter = exports.TimeFormats = exports.getTimeFormatterRegistry = void 0;
var _registry = require("@encodable/registry");
var _TimeFormatterRegistry = _interopRequireDefault(require("./TimeFormatterRegistry"));
exports.TimeFormatterRegistry = _TimeFormatterRegistry.default;
var _TimeFormats = _interopRequireWildcard(require("./TimeFormats"));
exports.TimeFormats = _TimeFormats.default;
exports.LOCAL_TIME_PREFIX = _TimeFormats.LOCAL_TIME_PREFIX;
var _createTimeFormatter = _interopRequireDefault(require("./createTimeFormatter"));
exports.createTimeFormatter = _createTimeFormatter.default;
var _previewTime = _interopRequireDefault(require("./previewTime"));
exports.previewTime = _previewTime.default;
var _createD3TimeFormatter = _interopRequireDefault(require("./factories/createD3TimeFormatter"));
exports.createD3TimeFormatter = _createD3TimeFormatter.default;
var _createMultiTimeFormatter = _interopRequireDefault(require("./factories/createMultiTimeFormatter"));
exports.createMultiTimeFormatter = _createMultiTimeFormatter.default;
var _smartDate = _interopRequireDefault(require("./formatters/smartDate"));
exports.smartDateFormatter = _smartDate.default;
var _smartDateVerbose = _interopRequireDefault(require("./formatters/smartDateVerbose"));
exports.smartDateVerboseFormatter = _smartDateVerbose.default;
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const getTimeFormatterRegistry = (0, _registry.makeSingleton)(() => new _TimeFormatterRegistry.default({
import { makeSingleton } from '@encodable/registry';
import TimeFormatterRegistry from './TimeFormatterRegistry';
export const getTimeFormatterRegistry = makeSingleton(() => new TimeFormatterRegistry({
globalId: '@encodable/format:TimeFormatterRegistry'
}));
exports.getTimeFormatterRegistry = getTimeFormatterRegistry;
function getTimeFormatter(format) {
export function getTimeFormatter(format) {
return getTimeFormatterRegistry().get(format);
}
function formatTime(format, value) {
export function formatTime(format, value) {
return getTimeFormatterRegistry().format(format, value);
}
}
export { TimeFormatterRegistry };
export { default as TimeFormats, LOCAL_TIME_PREFIX } from './TimeFormats';
export { default as createTimeFormatter } from './createTimeFormatter';
export { default as previewTime } from './previewTime';
export { default as createD3TimeFormatter } from './factories/createD3TimeFormatter';
export { default as createMultiTimeFormatter } from './factories/createMultiTimeFormatter';
export { default as smartDateFormatter } from './formatters/smartDate';
export { default as smartDateVerboseFormatter } from './formatters/smartDateVerbose';

@@ -1,11 +0,4 @@

"use strict";
exports.__esModule = true;
exports.default = previewTime;
exports.PREVIEW_TIME = void 0;
const PREVIEW_TIME = new Date(Date.UTC(2017, 1, 14, 11, 22, 33));
exports.PREVIEW_TIME = PREVIEW_TIME;
function previewTime(format, value = PREVIEW_TIME) {
export const PREVIEW_TIME = new Date(Date.UTC(2017, 1, 14, 11, 22, 33));
export default function previewTime(format, value = PREVIEW_TIME) {
return value.toUTCString() + " => " + format(value);
}

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

"use strict";
exports.__esModule = true;
exports.default = exports.LOCAL_TIME_PREFIX = void 0;
const LOCAL_TIME_PREFIX = 'local!';
exports.LOCAL_TIME_PREFIX = LOCAL_TIME_PREFIX;
export const LOCAL_TIME_PREFIX = 'local!';
const TimeFormats = {

@@ -15,3 +10,2 @@ DATABASE_DATE: '%Y-%m-%d',

};
var _default = TimeFormats;
exports.default = _default;
export default TimeFormats;

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

"use strict";
exports.__esModule = true;
exports.default = void 0;
var _TimeFormats = _interopRequireWildcard(require("./TimeFormats"));
var _createD3TimeFormatter = _interopRequireDefault(require("./factories/createD3TimeFormatter"));
var _prefix = require("../utils/prefix");
var _FormatterRegistry = _interopRequireDefault(require("../FormatterRegistry"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
class TimeFormatterRegistry extends _FormatterRegistry.default {
import TimeFormats, { LOCAL_TIME_PREFIX } from './TimeFormats';
import createD3TimeFormatter from './factories/createD3TimeFormatter';
import { removePrefix } from '../utils/prefix';
import FormatterRegistry from '../FormatterRegistry';
export default class TimeFormatterRegistry extends FormatterRegistry {
constructor({
defaultKey = _TimeFormats.default.DATABASE_DATETIME,
defaultKey = TimeFormats.DATABASE_DATETIME,
name = 'TimeFormatter',

@@ -35,10 +20,8 @@ ...rest

createFormatter(format) {
return (0, _createD3TimeFormatter.default)({
format: (0, _prefix.removePrefix)(_TimeFormats.LOCAL_TIME_PREFIX, format),
useLocalTime: format.startsWith(_TimeFormats.LOCAL_TIME_PREFIX)
return createD3TimeFormatter({
format: removePrefix(LOCAL_TIME_PREFIX, format),
useLocalTime: format.startsWith(LOCAL_TIME_PREFIX)
});
}
}
exports.default = TimeFormatterRegistry;
}

@@ -1,9 +0,4 @@

"use strict";
exports.__esModule = true;
exports.default = createTime;
function createTime(mode, year, month = 0, date = 1, hours = 0, minutes = 0, seconds = 0, milliseconds = 0) {
export default function createTime(mode, year, month = 0, date = 1, hours = 0, minutes = 0, seconds = 0, milliseconds = 0) {
const args = [year, month, date, hours, minutes, seconds, milliseconds];
return mode === 'local' ? new Date(...args) : new Date(Date.UTC(...args));
}

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

"use strict";
import { timeSecond, timeMinute, timeHour, timeDay, timeWeek, timeSunday, timeMonday, timeTuesday, timeWednesday, timeThursday, timeFriday, timeSaturday, timeMonth, timeYear, utcSecond, utcMinute, utcHour, utcDay, utcWeek, utcSunday, utcMonday, utcTuesday, utcWednesday, utcThursday, utcFriday, utcSaturday, utcMonth, utcYear } from 'd3-time';
exports.__esModule = true;
exports.localTimeUtils = exports.utcUtils = void 0;
var _d3Time = require("d3-time");
function createUtils(useLocalTime = false) {

@@ -25,31 +20,31 @@ let floorSecond;

if (useLocalTime) {
floorSecond = _d3Time.timeSecond;
floorMinute = _d3Time.timeMinute;
floorHour = _d3Time.timeHour;
floorDay = _d3Time.timeDay;
floorWeek = _d3Time.timeWeek;
floorWeekStartOnSunday = _d3Time.timeSunday;
floorWeekStartOnMonday = _d3Time.timeMonday;
floorWeekStartOnTuesday = _d3Time.timeTuesday;
floorWeekStartOnWednesday = _d3Time.timeWednesday;
floorWeekStartOnThursday = _d3Time.timeThursday;
floorWeekStartOnFriday = _d3Time.timeFriday;
floorWeekStartOnSaturday = _d3Time.timeSaturday;
floorMonth = _d3Time.timeMonth;
floorYear = _d3Time.timeYear;
floorSecond = timeSecond;
floorMinute = timeMinute;
floorHour = timeHour;
floorDay = timeDay;
floorWeek = timeWeek;
floorWeekStartOnSunday = timeSunday;
floorWeekStartOnMonday = timeMonday;
floorWeekStartOnTuesday = timeTuesday;
floorWeekStartOnWednesday = timeWednesday;
floorWeekStartOnThursday = timeThursday;
floorWeekStartOnFriday = timeFriday;
floorWeekStartOnSaturday = timeSaturday;
floorMonth = timeMonth;
floorYear = timeYear;
} else {
floorSecond = _d3Time.utcSecond;
floorMinute = _d3Time.utcMinute;
floorHour = _d3Time.utcHour;
floorDay = _d3Time.utcDay;
floorWeek = _d3Time.utcWeek;
floorWeekStartOnSunday = _d3Time.utcSunday;
floorWeekStartOnMonday = _d3Time.utcMonday;
floorWeekStartOnTuesday = _d3Time.utcTuesday;
floorWeekStartOnWednesday = _d3Time.utcWednesday;
floorWeekStartOnThursday = _d3Time.utcThursday;
floorWeekStartOnFriday = _d3Time.utcFriday;
floorWeekStartOnSaturday = _d3Time.utcSaturday;
floorMonth = _d3Time.utcMonth;
floorYear = _d3Time.utcYear;
floorSecond = utcSecond;
floorMinute = utcMinute;
floorHour = utcHour;
floorDay = utcDay;
floorWeek = utcWeek;
floorWeekStartOnSunday = utcSunday;
floorWeekStartOnMonday = utcMonday;
floorWeekStartOnTuesday = utcTuesday;
floorWeekStartOnWednesday = utcWednesday;
floorWeekStartOnThursday = utcThursday;
floorWeekStartOnFriday = utcFriday;
floorWeekStartOnSaturday = utcSaturday;
floorMonth = utcMonth;
floorYear = utcYear;
}

@@ -90,4 +85,3 @@

const utcUtils = createUtils();
exports.utcUtils = utcUtils;
const localTimeUtils = createUtils(true);
exports.localTimeUtils = localTimeUtils;
export { utcUtils, localTimeUtils };

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

"use strict";
exports.__esModule = true;
exports.default = createTimeRangeFormatter;
function createTimeRangeFormatter(formatFunc, metadata) {
export default function createTimeRangeFormatter(formatFunc, metadata) {
const format = value => formatFunc(value);

@@ -8,0 +3,0 @@

@@ -1,13 +0,4 @@

"use strict";
exports.__esModule = true;
exports.default = createNaiveTimeRangeFormatter;
var _createTimeRangeFormatter = _interopRequireDefault(require("../createTimeRangeFormatter"));
var _time = require("../../time");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createNaiveTimeRangeFormatter({
import createTimeRangeFormatter from '../createTimeRangeFormatter';
import { formatTime, getTimeFormatter } from '../../time';
export default function createNaiveTimeRangeFormatter({
format,

@@ -18,8 +9,8 @@ id,

}) {
return (0, _createTimeRangeFormatter.default)(range => {
const [start, end] = range.map(value => (0, _time.formatTime)(format, value));
return createTimeRangeFormatter(range => {
const [start, end] = range.map(value => formatTime(format, value));
return start === end ? start : [start, end].join(' — ');
}, {
id: id != null ? id : format,
useLocalTime: (0, _time.getTimeFormatter)(format).useLocalTime,
useLocalTime: getTimeFormatter(format).useLocalTime,
label,

@@ -26,0 +17,0 @@ description

@@ -1,27 +0,12 @@

"use strict";
exports.__esModule = true;
exports.getTimeRangeFormatter = getTimeRangeFormatter;
exports.formatTimeRange = formatTimeRange;
exports.getTimeRangeFormatterRegistry = void 0;
var _registry = require("@encodable/registry");
var _TimeRangeFormatterRegistry = _interopRequireDefault(require("./TimeRangeFormatterRegistry"));
exports.TimeRangeFormatterRegistry = _TimeRangeFormatterRegistry.default;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const getTimeRangeFormatterRegistry = (0, _registry.makeSingleton)(() => new _TimeRangeFormatterRegistry.default({
import { makeSingleton } from '@encodable/registry';
import TimeRangeFormatterRegistry from './TimeRangeFormatterRegistry';
export const getTimeRangeFormatterRegistry = makeSingleton(() => new TimeRangeFormatterRegistry({
globalId: '@encodable/format:TimeRangeFormatterRegistry'
}));
exports.getTimeRangeFormatterRegistry = getTimeRangeFormatterRegistry;
function getTimeRangeFormatter(format) {
export function getTimeRangeFormatter(format) {
return getTimeRangeFormatterRegistry().get(format);
}
function formatTimeRange(format, range) {
export function formatTimeRange(format, range) {
return getTimeRangeFormatter(format)(range);
}
}
export { TimeRangeFormatterRegistry };

@@ -1,17 +0,7 @@

"use strict";
exports.__esModule = true;
exports.default = void 0;
var _TimeFormats = _interopRequireDefault(require("../time/TimeFormats"));
var _createNaiveTimeRangeFormatter = _interopRequireDefault(require("./factories/createNaiveTimeRangeFormatter"));
var _FormatterRegistry = _interopRequireDefault(require("../FormatterRegistry"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class TimeRangeFormatterRegistry extends _FormatterRegistry.default {
import TimeFormats from '../time/TimeFormats';
import createNaiveTimeRangeFormatter from './factories/createNaiveTimeRangeFormatter';
import FormatterRegistry from '../FormatterRegistry';
export default class TimeRangeFormatterRegistry extends FormatterRegistry {
constructor({
defaultKey = _TimeFormats.default.DATABASE_DATETIME,
defaultKey = TimeFormats.DATABASE_DATETIME,
name = 'TimeRangeFormatter',

@@ -29,3 +19,3 @@ ...rest

createFormatter(format) {
return (0, _createNaiveTimeRangeFormatter.default)({
return createNaiveTimeRangeFormatter({
format

@@ -35,4 +25,2 @@ });

}
exports.default = TimeRangeFormatterRegistry;
}

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

"use strict";
exports.__esModule = true;
exports.default = fallbackFormatter;
function fallbackFormatter(v) {
export default function fallbackFormatter(v) {
return "" + v;
}

@@ -1,18 +0,9 @@

"use strict";
exports.__esModule = true;
exports.addPrefix = addPrefix;
exports.removePrefix = removePrefix;
exports.addSign = addSign;
function addPrefix(prefix, value) {
export function addPrefix(prefix, value) {
return value.startsWith(prefix) ? value : prefix + value;
}
function removePrefix(prefix, value) {
export function removePrefix(prefix, value) {
return value.startsWith(prefix) ? value.slice(prefix.length, value.length) : value;
}
function addSign(formatString) {
export function addSign(formatString) {
return addPrefix('+', formatString);
}
{
"name": "@encodable/format",
"version": "0.4.1",
"version": "0.4.2",
"description": "Encodable format",

@@ -31,3 +31,3 @@ "sideEffects": false,

"dependencies": {
"@encodable/registry": "^0.3.0",
"@encodable/registry": "^0.4.0",
"@types/d3-format": "^1.3.1",

@@ -40,3 +40,3 @@ "@types/d3-time": "^1.0.10",

},
"gitHead": "5a8a0ccfc183b8d5e58dafe2352a6190f2d76c39"
"gitHead": "2123b8cd1b8647d9a0c8a69e068027b65a4a7f2a"
}
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