dolphindb 3.1.53 → 3.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/browser.d.ts +1 -1
- package/browser.js +2 -1
- package/browser.js.map +1 -1
- package/index.d.ts +3 -1
- package/index.js +30 -16
- package/index.js.map +1 -1
- package/package.json +5 -5
- package/test.js.map +1 -1
package/index.d.ts
CHANGED
|
@@ -168,12 +168,14 @@ export interface InspectOptions extends UtilInspectOptions {
|
|
|
168
168
|
colors?: boolean;
|
|
169
169
|
/** `null` decimal places 小数位数 */
|
|
170
170
|
decimals?: number;
|
|
171
|
+
/** `在 format 中默认为 false,在 inspect 中默认为 true` 决定 null 值如何返回. nullstr ? 'null' : '' */
|
|
172
|
+
nullstr?: boolean;
|
|
171
173
|
/** `true` 决定格式化后的数据是否有千分位 */
|
|
172
174
|
grouping?: boolean;
|
|
173
175
|
/** timestamp 类型转换为字符串表示时显示到秒还是毫秒 */
|
|
174
176
|
timestamp?: 's' | 'ms';
|
|
175
177
|
}
|
|
176
|
-
/** 根据 DdbType 格式化单个元素 (value)
|
|
178
|
+
/** 根据 DdbType 格式化单个元素 (value) 为字符串,空值根据 nullstr 选项返回 'null' / '' 字符串 */
|
|
177
179
|
export declare function format(type: DdbType, value: DdbValue, le: boolean, options?: InspectOptions): string;
|
|
178
180
|
/** 格式化向量、集合中的第 index 项为字符串,空值返回 'null' 字符串 formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
|
|
179
181
|
export declare function formati(obj: DdbVectorObj, index: number, options?: InspectOptions): string;
|
package/index.js
CHANGED
|
@@ -1564,12 +1564,18 @@ export class DdbObj {
|
|
|
1564
1564
|
}
|
|
1565
1565
|
}
|
|
1566
1566
|
const gray_nullstr = 'null'.gray;
|
|
1567
|
+
function get_nullstr(options) {
|
|
1568
|
+
return options.nullstr ?
|
|
1569
|
+
options.colors ? gray_nullstr : 'null'
|
|
1570
|
+
:
|
|
1571
|
+
'';
|
|
1572
|
+
}
|
|
1567
1573
|
function format_time(type, value, options) {
|
|
1568
1574
|
if (value === null ||
|
|
1569
1575
|
value === ((type === DdbType.timestamp ||
|
|
1570
1576
|
type === DdbType.nanotime ||
|
|
1571
1577
|
type === DdbType.nanotimestamp) ? nulls.int64 : nulls.int32))
|
|
1572
|
-
return options
|
|
1578
|
+
return get_nullstr(options);
|
|
1573
1579
|
let str;
|
|
1574
1580
|
// formatter 可能会在 value 不属于 new Date() 有效值时,调用 抛出错误,这里统一处理
|
|
1575
1581
|
try {
|
|
@@ -1588,25 +1594,32 @@ function format_time(type, value, options) {
|
|
|
1588
1594
|
}
|
|
1589
1595
|
function format_number(type, value, options) {
|
|
1590
1596
|
return value === null || value === number_nulls.get(type) ?
|
|
1591
|
-
options
|
|
1597
|
+
get_nullstr(options)
|
|
1592
1598
|
: colored(get_number_formatter(type === DdbType.int || type === DdbType.long || type === DdbType.short, options.decimals, options.grouping).format(value), 'green', options.colors);
|
|
1593
1599
|
}
|
|
1594
|
-
/** 根据 DdbType 格式化单个元素 (value)
|
|
1600
|
+
/** 根据 DdbType 格式化单个元素 (value) 为字符串,空值根据 nullstr 选项返回 'null' / '' 字符串 */
|
|
1595
1601
|
export function format(type, value, le, options = {}) {
|
|
1596
1602
|
switch (type) {
|
|
1597
|
-
case DdbType.void:
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
null
|
|
1603
|
+
case DdbType.void:
|
|
1604
|
+
return options.nullstr ?
|
|
1605
|
+
value === DdbVoidType.default ?
|
|
1606
|
+
options.colors ? 'default'.gray : 'default'
|
|
1607
|
+
:
|
|
1608
|
+
options.colors ? gray_nullstr : 'null'
|
|
1604
1609
|
:
|
|
1605
|
-
|
|
1610
|
+
'';
|
|
1611
|
+
case DdbType.bool:
|
|
1612
|
+
if (value === null || value === nulls.int8)
|
|
1613
|
+
return get_nullstr(options);
|
|
1614
|
+
else {
|
|
1615
|
+
const str = String(Boolean(value));
|
|
1616
|
+
return options.colors ? str.blue : str;
|
|
1617
|
+
}
|
|
1606
1618
|
case DdbType.char:
|
|
1607
|
-
return
|
|
1608
|
-
|
|
1619
|
+
return value === null || value === nulls.int8 ?
|
|
1620
|
+
get_nullstr(options)
|
|
1609
1621
|
:
|
|
1622
|
+
inspect(
|
|
1610
1623
|
// ascii printable
|
|
1611
1624
|
// http://facweb.cs.depaul.edu/sjost/it212/documents/ascii-pr.htm
|
|
1612
1625
|
(32 <= value && value <= 126) ?
|
|
@@ -1678,13 +1691,13 @@ export function format(type, value, le, options = {}) {
|
|
|
1678
1691
|
const { scale, data } = value;
|
|
1679
1692
|
if (data === null ||
|
|
1680
1693
|
is_decimal_null_value(type, data))
|
|
1681
|
-
return
|
|
1694
|
+
return get_nullstr(options);
|
|
1682
1695
|
const s = String(data < 0 ? -data : data).padStart(scale, '0');
|
|
1683
1696
|
const str = (data < 0 ? '-' : '') + (scale ? `${s.slice(0, -scale) || '0'}.${s.slice(-scale)}` : s);
|
|
1684
1697
|
return options.colors ? str.green : str;
|
|
1685
1698
|
}
|
|
1686
1699
|
default:
|
|
1687
|
-
return inspect(value, options);
|
|
1700
|
+
return value === null ? get_nullstr(options) : inspect(value, options);
|
|
1688
1701
|
}
|
|
1689
1702
|
}
|
|
1690
1703
|
/** 格式化向量、集合中的第 index 项为字符串,空值返回 'null' 字符串 formatted vector, the index-th item in the collection is a string, a null value returns a 'null' string */
|
|
@@ -1858,7 +1871,8 @@ export function convert(type, value, le, { blob = 'string', char = 'string', tim
|
|
|
1858
1871
|
case DdbType.decimal32:
|
|
1859
1872
|
case DdbType.decimal64:
|
|
1860
1873
|
case DdbType.decimal128:
|
|
1861
|
-
|
|
1874
|
+
// 将表示 format 返回的表示空值的空字符串 '' 转为 null
|
|
1875
|
+
return format(type, value, le, { colors: false, timestamp }) || null;
|
|
1862
1876
|
default:
|
|
1863
1877
|
throw new Error(String(DdbType[type] || type) + t(' 暂时不支持转换为 js 对象'));
|
|
1864
1878
|
}
|