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.1.0 to 0.2.0

CHANGELOG.md

38

esm/index.js
"use strict";
exports.__esModule = true;
var _exportNames = {
fallbackFormatter: true
};
exports.fallbackFormatter = void 0;

@@ -9,5 +13,22 @@ var _number = require("./number");

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");

@@ -17,3 +38,18 @@

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 }; }

25

esm/number/createNumberFormatter.js

@@ -22,16 +22,19 @@ "use strict";

function createNumberFormatter({
id,
label,
description = '',
formatFunc,
isInvalid = false
}) {
function createNumberFormatter(formatFunc, metadata) {
const format = value => cleanAndFormat(value, formatFunc);
format.id = id;
format.label = label;
format.description = description;
format.isInvalid = isInvalid;
if (typeof metadata !== 'undefined') {
const {
id,
label,
description,
isInvalid = false
} = metadata;
format.id = id;
format.label = label;
format.description = description;
format.isInvalid = isInvalid;
}
return format;
}

@@ -13,3 +13,3 @@ "use strict";

function createD3NumberFormatter({
formatString,
format,
locale,

@@ -24,5 +24,5 @@ id,

try {
formatFunc = typeof locale === 'undefined' ? (0, _d3Format.format)(formatString) : (0, _d3Format.formatLocale)(locale).format(formatString);
formatFunc = typeof locale === 'undefined' ? (0, _d3Format.format)(format) : (0, _d3Format.formatLocale)(locale).format(format);
} catch (error) {
formatFunc = value => value + " (Invalid format: " + formatString + ")";
formatFunc = value => value + " (Invalid format: " + format + ")";

@@ -32,9 +32,8 @@ isInvalid = true;

return (0, _createNumberFormatter.default)({
formatFunc,
id: id != null ? id : formatString,
isInvalid,
return (0, _createNumberFormatter.default)(formatFunc, {
id: id != null ? id : format,
label,
description
description,
isInvalid
});
}

@@ -57,8 +57,7 @@ "use strict";

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

@@ -6,6 +6,4 @@ "use strict";

var _addSign = _interopRequireDefault(require("../utils/addSign"));
var _prefix = require("../utils/prefix");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const unsigned = {

@@ -31,3 +29,3 @@ CURRENCY: '$,.2f',

// eslint-disable-next-line no-param-reassign
prev[key] = (0, _addSign.default)(value);
prev[key] = (0, _prefix.addSign)(value);
return prev;

@@ -34,0 +32,0 @@ }, {});

@@ -6,4 +6,2 @@ "use strict";

var _registry = require("@encodable/registry");
var _createD3NumberFormatter = _interopRequireDefault(require("./factories/createD3NumberFormatter"));

@@ -15,8 +13,9 @@

var _FormatterRegistry = _interopRequireDefault(require("../FormatterRegistry"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class NumberFormatterRegistry extends _registry.SyncRegistry {
class NumberFormatterRegistry extends _FormatterRegistry.default {
constructor({
name = 'NumberFormatter',
overwritePolicy = _registry.OverwritePolicy.WARN,
...rest

@@ -26,3 +25,2 @@ } = {}) {

name,
overwritePolicy,
...rest

@@ -35,25 +33,13 @@ });

this.setDefaultKey(_NumberFormats.default.SMART_NUMBER);
}
} // eslint-disable-next-line class-methods-use-this
get(formatterId) {
const targetFormat = ("" + (formatterId === null || typeof formatterId === 'undefined' || formatterId === '' ? this.getDefaultKey() : formatterId)).trim();
if (this.has(targetFormat)) {
return super.get(targetFormat);
} // Create new formatter if does not exist
const formatter = (0, _createD3NumberFormatter.default)({
formatString: targetFormat
createFormatter(format) {
return (0, _createD3NumberFormatter.default)({
format
});
this.registerValue(targetFormat, formatter);
return formatter;
}
format(formatterId, value) {
return this.get(formatterId)(value);
}
}
exports.default = NumberFormatterRegistry;
export * from './number';
export * from './time';
export * from './timeRange';
export * from './types';
export { default as fallbackFormatter } from './utils/fallbackFormatter';
export * from './utils/prefix';
//# sourceMappingURL=index.d.ts.map
"use strict";
exports.__esModule = true;
var _exportNames = {
fallbackFormatter: true
};
exports.fallbackFormatter = void 0;

@@ -9,5 +13,22 @@ var _number = require("./number");

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");

@@ -17,3 +38,18 @@

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 }; }

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

import { NumberFormatter, NumberFormatterConfig } from '../types';
export default function createNumberFormatter({ id, label, description, formatFunc, isInvalid, }: NumberFormatterConfig): NumberFormatter;
import { NumberFormatter, NumberFormatFunction, NumberFormatterMetadata } from '../types';
export default function createNumberFormatter(formatFunc: NumberFormatFunction, metadata?: NumberFormatterMetadata): NumberFormatter;
//# sourceMappingURL=createNumberFormatter.d.ts.map

@@ -22,16 +22,19 @@ "use strict";

function createNumberFormatter({
id,
label,
description = '',
formatFunc,
isInvalid = false
}) {
function createNumberFormatter(formatFunc, metadata) {
const format = value => cleanAndFormat(value, formatFunc);
format.id = id;
format.label = label;
format.description = description;
format.isInvalid = isInvalid;
if (typeof metadata !== 'undefined') {
const {
id,
label,
description,
isInvalid = false
} = metadata;
format.id = id;
format.label = label;
format.description = description;
format.isInvalid = isInvalid;
}
return format;
}
import { FormatLocaleDefinition } from 'd3-format';
import { NumberFormatterConfig } from '../../types';
declare type Config = Omit<NumberFormatterConfig, 'formatFunc'> & {
formatString: string;
import { NumberFormatterMetadata } from '../../types';
interface Config extends NumberFormatterMetadata {
format: string;
locale?: FormatLocaleDefinition;
};
export default function createD3NumberFormatter({ formatString, locale, id, label, description, }: Config): import("../../types").NumberFormatter;
}
export default function createD3NumberFormatter({ format, locale, id, label, description, }: Config): import("../../types").NumberFormatter;
export {};
//# sourceMappingURL=createD3NumberFormatter.d.ts.map

@@ -13,3 +13,3 @@ "use strict";

function createD3NumberFormatter({
formatString,
format,
locale,

@@ -24,5 +24,5 @@ id,

try {
formatFunc = typeof locale === 'undefined' ? (0, _d3Format.format)(formatString) : (0, _d3Format.formatLocale)(locale).format(formatString);
formatFunc = typeof locale === 'undefined' ? (0, _d3Format.format)(format) : (0, _d3Format.formatLocale)(locale).format(format);
} catch (error) {
formatFunc = value => value + " (Invalid format: " + formatString + ")";
formatFunc = value => value + " (Invalid format: " + format + ")";

@@ -32,9 +32,8 @@ isInvalid = true;

return (0, _createNumberFormatter.default)({
formatFunc,
id: id != null ? id : formatString,
isInvalid,
return (0, _createNumberFormatter.default)(formatFunc, {
id: id != null ? id : format,
label,
description
description,
isInvalid
});
}

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

import { NumberFormatterConfig } from '../../types';
declare type Config = Omit<NumberFormatterConfig, 'formatFunc'> & {
import { NumberFormatterMetadata } from '../../types';
interface Config extends NumberFormatterMetadata {
signed?: boolean;
};
}
export default function createSmartNumberFormatter({ signed, id, label, description, }?: Config): import("../../types").NumberFormatter;
export {};
//# sourceMappingURL=createSmartNumberFormatter.d.ts.map

@@ -57,8 +57,7 @@ "use strict";

const getSign = signed ? ADD_PLUS : BLANK;
return (0, _createNumberFormatter.default)({
description,
formatFunc: value => "" + getSign(value) + formatValue(value),
return (0, _createNumberFormatter.default)(value => "" + getSign(value) + formatValue(value), {
id: (id != null ? id : signed) ? _NumberFormats.default.signed.SMART_NUMBER : _NumberFormats.default.SMART_NUMBER,
label: label != null ? label : 'Adaptive formatter'
label: label != null ? label : 'Adaptive formatter',
description
});
}
import NumberFormatterRegistry from './NumberFormatterRegistry';
import { NumberFormatInput } from '../types';
export declare const getNumberFormatterRegistry: () => NumberFormatterRegistry;
export declare function getNumberFormatter(format?: string): import("..").NumberFormatter;
export declare function formatNumber(format: string | undefined, value: number | null | undefined): string;
export declare function getNumberFormatter(format?: string): import("../types").NumberFormatter;
export declare function formatNumber(format: string | undefined, value: NumberFormatInput): string;
export { NumberFormatterRegistry };

@@ -6,0 +7,0 @@ export { default as NumberFormats } from './NumberFormats';

declare const _default: {
signed: Record<"SMART_NUMBER" | "CURRENCY" | "CURRENCY_ROUND" | "FLOAT_1_POINT" | "FLOAT_2_POINT" | "FLOAT_3_POINT" | "FLOAT" | "INTEGER" | "PERCENT_1_POINT" | "PERCENT_2_POINT" | "PERCENT_3_POINT" | "PERCENT" | "SI_1_DIGIT" | "SI_2_DIGIT" | "SI_3_DIGIT" | "SI", string>;
CURRENCY: "$,.2f";
CURRENCY_ROUND: "$,d";
FLOAT_1_POINT: ",.1f";
FLOAT_2_POINT: ",.2f";
FLOAT_3_POINT: ",.3f";
FLOAT: ",.2f";
INTEGER: ",d";
PERCENT_1_POINT: ",.1%";
PERCENT_2_POINT: ",.2%";
PERCENT_3_POINT: ",.3%";
PERCENT: ",.2%";
SI_1_DIGIT: ".1s";
SI_2_DIGIT: ".2s";
SI_3_DIGIT: ".3s";
SI: ".3s";
SMART_NUMBER: "SMART_NUMBER";
CURRENCY: string;
CURRENCY_ROUND: string;
FLOAT_1_POINT: string;
FLOAT_2_POINT: string;
FLOAT_3_POINT: string;
FLOAT: string;
INTEGER: string;
PERCENT_1_POINT: string;
PERCENT_2_POINT: string;
PERCENT_3_POINT: string;
PERCENT: string;
SI_1_DIGIT: string;
SI_2_DIGIT: string;
SI_3_DIGIT: string;
SI: string;
SMART_NUMBER: string;
};
export default _default;
//# sourceMappingURL=NumberFormats.d.ts.map

@@ -6,6 +6,4 @@ "use strict";

var _addSign = _interopRequireDefault(require("../utils/addSign"));
var _prefix = require("../utils/prefix");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const unsigned = {

@@ -31,3 +29,3 @@ CURRENCY: '$,.2f',

// eslint-disable-next-line no-param-reassign
prev[key] = (0, _addSign.default)(value);
prev[key] = (0, _prefix.addSign)(value);
return prev;

@@ -34,0 +32,0 @@ }, {});

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

import { SyncRegistry, RegistryConfig } from '@encodable/registry';
import { RegistryConfig } from '@encodable/registry';
import { NumberFormatter } from '../types';
export default class NumberFormatterRegistry extends SyncRegistry<NumberFormatter> {
constructor({ name, overwritePolicy, ...rest }?: RegistryConfig);
get(formatterId?: string): NumberFormatter;
format(formatterId: string | undefined, value: number | null | undefined): string;
import FormatterRegistry from '../FormatterRegistry';
export default class NumberFormatterRegistry extends FormatterRegistry<NumberFormatter> {
constructor({ name, ...rest }?: RegistryConfig);
protected createFormatter(format: string): NumberFormatter;
}
//# sourceMappingURL=NumberFormatterRegistry.d.ts.map

@@ -6,4 +6,2 @@ "use strict";

var _registry = require("@encodable/registry");
var _createD3NumberFormatter = _interopRequireDefault(require("./factories/createD3NumberFormatter"));

@@ -15,8 +13,9 @@

var _FormatterRegistry = _interopRequireDefault(require("../FormatterRegistry"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class NumberFormatterRegistry extends _registry.SyncRegistry {
class NumberFormatterRegistry extends _FormatterRegistry.default {
constructor({
name = 'NumberFormatter',
overwritePolicy = _registry.OverwritePolicy.WARN,
...rest

@@ -26,3 +25,2 @@ } = {}) {

name,
overwritePolicy,
...rest

@@ -35,25 +33,13 @@ });

this.setDefaultKey(_NumberFormats.default.SMART_NUMBER);
}
} // eslint-disable-next-line class-methods-use-this
get(formatterId) {
const targetFormat = ("" + (formatterId === null || typeof formatterId === 'undefined' || formatterId === '' ? this.getDefaultKey() : formatterId)).trim();
if (this.has(targetFormat)) {
return super.get(targetFormat);
} // Create new formatter if does not exist
const formatter = (0, _createD3NumberFormatter.default)({
formatString: targetFormat
createFormatter(format) {
return (0, _createD3NumberFormatter.default)({
format
});
this.registerValue(targetFormat, formatter);
return formatter;
}
format(formatterId, value) {
return this.get(formatterId)(value);
}
}
exports.default = NumberFormatterRegistry;

@@ -1,16 +0,27 @@

export declare type NumberFormatFunction = (value: number) => string;
export interface NumberFormatterConfig {
formatFunc: NumberFormatFunction;
interface FormatterMetadata {
id?: string;
label?: string;
description?: string;
isInvalid?: boolean;
}
export interface NumberFormatter {
(value: number | null | undefined): string;
id?: string;
label?: string;
description?: string;
export declare type NumberFormatInput = number | null | undefined;
export declare type NumberFormatFunction = (value: number) => string;
export interface NumberFormatterMetadata extends FormatterMetadata {
isInvalid?: boolean;
}
export interface NumberFormatter extends NumberFormatterMetadata {
(value: NumberFormatInput): string;
}
export declare type TimeFormatInput = Date | number | null | undefined;
export declare type TimeFormatFunction = (value: Date) => string;
export interface TimeFormatterMetadata extends FormatterMetadata {
useLocalTime?: boolean;
}
export interface TimeFormatter extends TimeFormatterMetadata {
(value: TimeFormatInput): string;
}
export declare type TimeRangeFormatFunction = (values: TimeFormatInput[]) => string;
export interface TimeRangeFormatter extends TimeFormatterMetadata {
(value: TimeFormatInput[]): string;
}
export {};
//# sourceMappingURL=index.d.ts.map
{
"name": "@encodable/format",
"version": "0.1.0",
"version": "0.2.0",
"description": "Encodable format",

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

},
"gitHead": "e20b6d37d5e432c5050c7ba0730d7b51ef3f8b56"
"gitHead": "b94c9441e2dec725cfa27ba0fbafb547876cf631"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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