chore(number-formatter): upgrade pretty-ms to 9.1.0 (#30599)
This commit is contained in:
parent
55f18a34a9
commit
7132d5a86a
|
|
@ -56,7 +56,7 @@ module.exports = {
|
|||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
|
||||
snapshotSerializers: ['@emotion/jest/enzyme-serializer'],
|
||||
transformIgnorePatterns: [
|
||||
'node_modules/(?!d3-(interpolate|color|time)|remark-gfm|markdown-table|micromark-*.|decode-named-character-reference|character-entities|mdast-util-*.|unist-util-*.|ccount|escape-string-regexp|nanoid|@rjsf/*.|sinon|echarts|zrender|fetch-mock)',
|
||||
'node_modules/(?!d3-(interpolate|color|time)|remark-gfm|markdown-table|micromark-*.|decode-named-character-reference|character-entities|mdast-util-*.|unist-util-*.|ccount|escape-string-regexp|nanoid|@rjsf/*.|sinon|echarts|zrender|fetch-mock|pretty-ms|parse-ms)',
|
||||
],
|
||||
globals: {
|
||||
__DEV__: true,
|
||||
|
|
|
|||
|
|
@ -42976,13 +42976,6 @@
|
|||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/parse-ms": {
|
||||
"version": "2.1.0",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/parse-node-version": {
|
||||
"version": "1.0.1",
|
||||
"dev": true,
|
||||
|
|
@ -44119,19 +44112,6 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/pretty-ms": {
|
||||
"version": "7.0.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"parse-ms": "^2.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/prismjs": {
|
||||
"version": "1.27.0",
|
||||
"license": "MIT",
|
||||
|
|
@ -55984,7 +55964,7 @@
|
|||
"jed": "^1.1.1",
|
||||
"lodash": "^4.17.21",
|
||||
"math-expression-evaluator": "^1.3.8",
|
||||
"pretty-ms": "^7.0.0",
|
||||
"pretty-ms": "^9.1.0",
|
||||
"react-error-boundary": "^1.2.5",
|
||||
"react-markdown": "^8.0.7",
|
||||
"rehype-raw": "^7.0.0",
|
||||
|
|
@ -56414,6 +56394,25 @@
|
|||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"packages/superset-ui-core/node_modules/parse-ms": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-4.0.0.tgz",
|
||||
"integrity": "sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"packages/superset-ui-core/node_modules/pretty-ms": {
|
||||
"version": "9.1.0",
|
||||
"resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.1.0.tgz",
|
||||
"integrity": "sha512-o1piW0n3tgKIKCwk2vpM/vOV13zjJzvP37Ioze54YlTHE06m4tjEbzg9WsKkvTuyYln2DHjo5pY4qrZGI0otpw==",
|
||||
"dependencies": {
|
||||
"parse-ms": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"packages/superset-ui-core/node_modules/remark-gfm": {
|
||||
"version": "3.0.1",
|
||||
"license": "MIT",
|
||||
|
|
@ -66353,7 +66352,7 @@
|
|||
"jest-mock-console": "^2.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"math-expression-evaluator": "^1.3.8",
|
||||
"pretty-ms": "^7.0.0",
|
||||
"pretty-ms": "^9.1.0",
|
||||
"react-error-boundary": "^1.2.5",
|
||||
"react-markdown": "^8.0.7",
|
||||
"rehype-raw": "^7.0.0",
|
||||
|
|
@ -66629,6 +66628,19 @@
|
|||
"uvu": "^0.5.0"
|
||||
}
|
||||
},
|
||||
"parse-ms": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-4.0.0.tgz",
|
||||
"integrity": "sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw=="
|
||||
},
|
||||
"pretty-ms": {
|
||||
"version": "9.1.0",
|
||||
"resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.1.0.tgz",
|
||||
"integrity": "sha512-o1piW0n3tgKIKCwk2vpM/vOV13zjJzvP37Ioze54YlTHE06m4tjEbzg9WsKkvTuyYln2DHjo5pY4qrZGI0otpw==",
|
||||
"requires": {
|
||||
"parse-ms": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"remark-gfm": {
|
||||
"version": "3.0.1",
|
||||
"requires": {
|
||||
|
|
@ -88446,9 +88458,6 @@
|
|||
"json-parse-better-errors": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"parse-ms": {
|
||||
"version": "2.1.0"
|
||||
},
|
||||
"parse-node-version": {
|
||||
"version": "1.0.1",
|
||||
"dev": true
|
||||
|
|
@ -89110,12 +89119,6 @@
|
|||
"pretty-hrtime": {
|
||||
"version": "1.0.3"
|
||||
},
|
||||
"pretty-ms": {
|
||||
"version": "7.0.1",
|
||||
"requires": {
|
||||
"parse-ms": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"prismjs": {
|
||||
"version": "1.27.0"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
"jed": "^1.1.1",
|
||||
"lodash": "^4.17.21",
|
||||
"math-expression-evaluator": "^1.3.8",
|
||||
"pretty-ms": "^7.0.0",
|
||||
"pretty-ms": "^9.1.0",
|
||||
"react-error-boundary": "^1.2.5",
|
||||
"react-markdown": "^8.0.7",
|
||||
"rehype-raw": "^7.0.0",
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import prettyMsFormatter from 'pretty-ms';
|
||||
import prettyMilliseconds, { Options } from 'pretty-ms';
|
||||
import NumberFormatter from '../NumberFormatter';
|
||||
|
||||
export default function createDurationFormatter(
|
||||
|
|
@ -26,13 +26,14 @@ export default function createDurationFormatter(
|
|||
id?: string;
|
||||
label?: string;
|
||||
multiplier?: number;
|
||||
} & prettyMsFormatter.Options = {},
|
||||
} & Options = {},
|
||||
) {
|
||||
const { description, id, label, multiplier = 1, ...prettyMsOptions } = config;
|
||||
|
||||
return new NumberFormatter({
|
||||
description,
|
||||
formatFunc: value => prettyMsFormatter(value * multiplier, prettyMsOptions),
|
||||
formatFunc: value =>
|
||||
prettyMilliseconds(value * multiplier, prettyMsOptions),
|
||||
id: id ?? 'duration_format',
|
||||
label: label ?? `Duration formatter`,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,40 +19,41 @@
|
|||
|
||||
import { NumberFormatter, createDurationFormatter } from '@superset-ui/core';
|
||||
|
||||
describe('createDurationFormatter()', () => {
|
||||
it('creates an instance of NumberFormatter', () => {
|
||||
const formatter = createDurationFormatter();
|
||||
expect(formatter).toBeInstanceOf(NumberFormatter);
|
||||
});
|
||||
it('format milliseconds in human readable format with default options', () => {
|
||||
const formatter = createDurationFormatter();
|
||||
expect(formatter(0)).toBe('0ms');
|
||||
expect(formatter(1000)).toBe('1s');
|
||||
expect(formatter(1337)).toBe('1.3s');
|
||||
expect(formatter(10500)).toBe('10.5s');
|
||||
expect(formatter(60 * 1000)).toBe('1m');
|
||||
expect(formatter(90 * 1000)).toBe('1m 30s');
|
||||
});
|
||||
it('format seconds in human readable format with default options', () => {
|
||||
const formatter = createDurationFormatter({ multiplier: 1000 });
|
||||
expect(formatter(0.5)).toBe('500ms');
|
||||
expect(formatter(1)).toBe('1s');
|
||||
expect(formatter(30)).toBe('30s');
|
||||
expect(formatter(60)).toBe('1m');
|
||||
expect(formatter(90)).toBe('1m 30s');
|
||||
});
|
||||
it('format milliseconds in human readable format with additional pretty-ms options', () => {
|
||||
const colonNotationFormatter = createDurationFormatter({
|
||||
colonNotation: true,
|
||||
});
|
||||
expect(colonNotationFormatter(10500)).toBe('0:10.5');
|
||||
const zeroDecimalFormatter = createDurationFormatter({
|
||||
secondsDecimalDigits: 0,
|
||||
});
|
||||
expect(zeroDecimalFormatter(10500)).toBe('10s');
|
||||
const subMillisecondFormatter = createDurationFormatter({
|
||||
formatSubMilliseconds: true,
|
||||
});
|
||||
expect(subMillisecondFormatter(100.40008)).toBe('100ms 400µs 80ns');
|
||||
});
|
||||
test('creates an instance of NumberFormatter', () => {
|
||||
const formatter = createDurationFormatter();
|
||||
expect(formatter).toBeInstanceOf(NumberFormatter);
|
||||
});
|
||||
test('format milliseconds in human readable format with default options', () => {
|
||||
const formatter = createDurationFormatter();
|
||||
expect(formatter(-1000)).toBe('-1s');
|
||||
expect(formatter(0)).toBe('0ms');
|
||||
expect(formatter(1000)).toBe('1s');
|
||||
expect(formatter(1337)).toBe('1.3s');
|
||||
expect(formatter(10500)).toBe('10.5s');
|
||||
expect(formatter(60 * 1000)).toBe('1m');
|
||||
expect(formatter(90 * 1000)).toBe('1m 30s');
|
||||
});
|
||||
test('format seconds in human readable format with default options', () => {
|
||||
const formatter = createDurationFormatter({ multiplier: 1000 });
|
||||
expect(formatter(-0.5)).toBe('-500ms');
|
||||
expect(formatter(0.5)).toBe('500ms');
|
||||
expect(formatter(1)).toBe('1s');
|
||||
expect(formatter(30)).toBe('30s');
|
||||
expect(formatter(60)).toBe('1m');
|
||||
expect(formatter(90)).toBe('1m 30s');
|
||||
});
|
||||
test('format milliseconds in human readable format with additional pretty-ms options', () => {
|
||||
const colonNotationFormatter = createDurationFormatter({
|
||||
colonNotation: true,
|
||||
});
|
||||
expect(colonNotationFormatter(-10500)).toBe('-0:10.5');
|
||||
expect(colonNotationFormatter(10500)).toBe('0:10.5');
|
||||
const zeroDecimalFormatter = createDurationFormatter({
|
||||
secondsDecimalDigits: 0,
|
||||
});
|
||||
expect(zeroDecimalFormatter(10500)).toBe('10s');
|
||||
const subMillisecondFormatter = createDurationFormatter({
|
||||
formatSubMilliseconds: true,
|
||||
});
|
||||
expect(subMillisecondFormatter(100.40008)).toBe('100ms 400µs 80ns');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue