Skip to content

Commit

Permalink
Expose factory functions as public API (apache#43)
Browse files Browse the repository at this point in the history
feat: Expose factory functions through API
  • Loading branch information
kristw authored Nov 30, 2018
1 parent 2838a17 commit d0cc957
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 58 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @superset-ui -- Changelog

## v0.7.1

### ✨ Features

* Add new APIs to `@superset-ui/time-format`
- `createD3TimeFormatter`
- `createMultiFormatter`
* Add new APIs to `@superset-ui/number-format`
- `createD3NumberFormatter`
- `createSiAtMostNDigitFormatter`

## v0.7.0

### ✨ Features
Expand Down
94 changes: 63 additions & 31 deletions packages/superset-ui-number-format/src/NumberFormats.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,63 @@
export const DOLLAR = '$,.2f';
export const DOLLAR_CHANGE = '+$,.2f';
export const DOLLAR_ROUND = '$,d';
export const DOLLAR_ROUND_CHANGE = '+$,d';

export const FLOAT_1_POINT = ',.1f';
export const FLOAT_2_POINT = ',.2f';
export const FLOAT_3_POINT = ',.3f';
export const FLOAT = FLOAT_2_POINT;

export const FLOAT_CHANGE_1_POINT = '+,.1f';
export const FLOAT_CHANGE_2_POINT = '+,.2f';
export const FLOAT_CHANGE_3_POINT = '+,.3f';
export const FLOAT_CHANGE = FLOAT_CHANGE_2_POINT;

export const INTEGER = ',d';
export const INTEGER_CHANGE = '+,d';

export const PERCENT_1_POINT = ',.1%';
export const PERCENT_2_POINT = ',.2%';
export const PERCENT_3_POINT = ',.3%';
export const PERCENT = PERCENT_2_POINT;

export const PERCENT_CHANGE_1_POINT = '+,.1%';
export const PERCENT_CHANGE_2_POINT = '+,.2%';
export const PERCENT_CHANGE_3_POINT = '+,.3%';
export const PERCENT_CHANGE = PERCENT_CHANGE_2_POINT;

export const SI_1_DIGIT = '.1s';
export const SI_2_DIGIT = '.2s';
export const SI_3_DIGIT = '.3s';
const DOLLAR = '$,.2f';
const DOLLAR_CHANGE = '+$,.2f';
const DOLLAR_ROUND = '$,d';
const DOLLAR_ROUND_CHANGE = '+$,d';

const FLOAT_1_POINT = ',.1f';
const FLOAT_2_POINT = ',.2f';
const FLOAT_3_POINT = ',.3f';
const FLOAT = FLOAT_2_POINT;

const FLOAT_CHANGE_1_POINT = '+,.1f';
const FLOAT_CHANGE_2_POINT = '+,.2f';
const FLOAT_CHANGE_3_POINT = '+,.3f';
const FLOAT_CHANGE = FLOAT_CHANGE_2_POINT;

const INTEGER = ',d';
const INTEGER_CHANGE = '+,d';

const PERCENT_1_POINT = ',.1%';
const PERCENT_2_POINT = ',.2%';
const PERCENT_3_POINT = ',.3%';
const PERCENT = PERCENT_2_POINT;

const PERCENT_CHANGE_1_POINT = '+,.1%';
const PERCENT_CHANGE_2_POINT = '+,.2%';
const PERCENT_CHANGE_3_POINT = '+,.3%';
const PERCENT_CHANGE = PERCENT_CHANGE_2_POINT;

const SI_1_DIGIT = '.1s';
const SI_2_DIGIT = '.2s';
const SI_3_DIGIT = '.3s';
const SI = SI_3_DIGIT;

const NumberFormats = {
DOLLAR,
DOLLAR_CHANGE,
DOLLAR_ROUND,
DOLLAR_ROUND_CHANGE,
FLOAT,
FLOAT_1_POINT,
FLOAT_2_POINT,
FLOAT_3_POINT,
FLOAT_CHANGE,
FLOAT_CHANGE_1_POINT,
FLOAT_CHANGE_2_POINT,
FLOAT_CHANGE_3_POINT,
INTEGER,
INTEGER_CHANGE,
PERCENT,
PERCENT_1_POINT,
PERCENT_2_POINT,
PERCENT_3_POINT,
PERCENT_CHANGE,
PERCENT_CHANGE_1_POINT,
PERCENT_CHANGE_2_POINT,
PERCENT_CHANGE_3_POINT,
SI,
SI_1_DIGIT,
SI_2_DIGIT,
SI_3_DIGIT,
};

export default NumberFormats;
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { RegistryWithDefaultKey } from '@superset-ui/core';
import createD3NumberFormatter from './factories/createD3NumberFormatter';
import { SI_3_DIGIT } from './NumberFormats';

const DEFAULT_FORMAT = SI_3_DIGIT;
import NumberFormats from './NumberFormats';

export default class NumberFormatterRegistry extends RegistryWithDefaultKey {
constructor() {
super({
initialDefaultKey: DEFAULT_FORMAT,
initialDefaultKey: NumberFormats.SI,
name: 'NumberFormatter',
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function createSiAtMostNDigitFormatter({ description, n = 3, id,
formatFunc: value => {
const si = siFormatter(value);

// Removing trailing `.00` if any
/* Removing trailing `.00` if any */
return si.slice(-1) < 'A' ? parseFloat(si).toString() : si;
},
id: id || `si_at_most_${n}_digit`,
Expand Down
9 changes: 6 additions & 3 deletions packages/superset-ui-number-format/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as NumberFormats from './NumberFormats';
export { default as NumberFormats } from './NumberFormats';
export { default as NumberFormatter, PREVIEW_VALUE } from './NumberFormatter';

export {
default as getNumberFormatterRegistry,
formatNumber,
getNumberFormatter,
} from './NumberFormatterRegistrySingleton';

export { default as NumberFormatter, PREVIEW_VALUE } from './NumberFormatter';
export { NumberFormats };
export { default as createD3NumberFormatter } from './factories/createD3NumberFormatter';
export {
default as createSiAtMostNDigitFormatter,
} from './factories/createSiAtMostNDigitFormatter';
8 changes: 6 additions & 2 deletions packages/superset-ui-number-format/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import {
createD3NumberFormatter,
createSiAtMostNDigitFormatter,
formatNumber,
NumberFormats,
getNumberFormatter,
getNumberFormatterRegistry,
NumberFormats,
NumberFormatter,
PREVIEW_VALUE,
} from '../src/index';

describe('index', () => {
it('exports modules', () => {
[
createD3NumberFormatter,
createSiAtMostNDigitFormatter,
formatNumber,
NumberFormats,
getNumberFormatter,
getNumberFormatterRegistry,
NumberFormats,
NumberFormatter,
PREVIEW_VALUE,
].forEach(x => expect(x).toBeDefined());
Expand Down
23 changes: 17 additions & 6 deletions packages/superset-ui-time-format/src/TimeFormats.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
export const LOCAL_PREFIX = 'local!';

export const DATABASE_DATETIME = '%Y-%m-%d %H:%M:%S';
export const DATABASE_DATETIME_REVERSE = '%d-%m-%Y %H:%M:%S';
export const US_DATE = '%m/%d/%Y';
export const INTERNATIONAL_DATE = '%d/%m/%Y';
export const DATABASE_DATE = '%Y-%m-%d';
export const TIME = '%H:%M:%S';
const DATABASE_DATETIME = '%Y-%m-%d %H:%M:%S';
const DATABASE_DATETIME_REVERSE = '%d-%m-%Y %H:%M:%S';
const US_DATE = '%m/%d/%Y';
const INTERNATIONAL_DATE = '%d/%m/%Y';
const DATABASE_DATE = '%Y-%m-%d';
const TIME = '%H:%M:%S';

const TimeFormats = {
DATABASE_DATE,
DATABASE_DATETIME,
DATABASE_DATETIME_REVERSE,
INTERNATIONAL_DATE,
TIME,
US_DATE,
};

export default TimeFormats;
6 changes: 2 additions & 4 deletions packages/superset-ui-time-format/src/TimeFormatterRegistry.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { RegistryWithDefaultKey } from '@superset-ui/core';
import { DATABASE_DATETIME, LOCAL_PREFIX } from './TimeFormats';
import TimeFormats, { LOCAL_PREFIX } from './TimeFormats';
import createD3TimeFormatter from './factories/createD3TimeFormatter';

const DEFAULT_FORMAT = DATABASE_DATETIME;

export default class TimeFormatterRegistry extends RegistryWithDefaultKey {
constructor() {
super({
initialDefaultKey: DEFAULT_FORMAT,
initialDefaultKey: TimeFormats.DATABASE_DATETIME,
name: 'TimeFormatter',
});
}
Expand Down
10 changes: 7 additions & 3 deletions packages/superset-ui-time-format/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import * as TimeFormats from './TimeFormats';
export { default as TimeFormats, LOCAL_PREFIX } from './TimeFormats';
export { default as TimeFormatter, PREVIEW_TIME } from './TimeFormatter';

export {
default as getTimeFormatterRegistry,
formatTime,
getTimeFormatter,
} from './TimeFormatterRegistrySingleton';

export { default as TimeFormatter, PREVIEW_TIME } from './TimeFormatter';
export { TimeFormats };
export { default as createD3TimeFormatter } from './factories/createD3TimeFormatter';
export { default as createMultiFormatter } from './factories/createMultiFormatter';

export { default as smartDateFormatter } from './formatters/smartDate';
export { default as smartDateVerboseFormatter } from './formatters/smartDateVerbose';
18 changes: 14 additions & 4 deletions packages/superset-ui-time-format/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import {
createD3TimeFormatter,
createMultiFormatter,
formatTime,
TimeFormats,
getTimeFormatter,
getTimeFormatterRegistry,
TimeFormatter,
LOCAL_PREFIX,
PREVIEW_TIME,
smartDateFormatter,
smartDateVerboseFormatter,
TimeFormats,
TimeFormatter,
} from '../src/index';

describe('index', () => {
it('exports modules', () => {
[
createD3TimeFormatter,
createMultiFormatter,
formatTime,
TimeFormats,
getTimeFormatter,
getTimeFormatterRegistry,
TimeFormatter,
LOCAL_PREFIX,
PREVIEW_TIME,
smartDateFormatter,
smartDateVerboseFormatter,
TimeFormats,
TimeFormatter,
].forEach(x => expect(x).toBeDefined());
});
});

0 comments on commit d0cc957

Please sign in to comment.