-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathType.ToText_simple.pq
More file actions
45 lines (45 loc) · 2.02 KB
/
Type.ToText_simple.pq
File metadata and controls
45 lines (45 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
let
/*
dependencies: None
*/
Type.ToText.Type = type function(
typeInfo as (type any meta [
Documentation.FieldCaption = "Object to test",
Documentation.FieldDescription = "Value to compare type names against",
Documentation.SampleValues = {
23.45, "string", DateTime.LocalNow()
//, #table(type table[Text = text],{{"hi world"}})
}
]),
optional options as (type record meta [
Documentation.FieldCaption = "for future formatting",
Documentation.FieldDescription = "for future formatting",
Documentation.SampleValues = {
}
])) as table meta [
Documentation.Name = "Get Type Name",
Documentation.LongDescription = "Returns type names as text, for the current value",
Documentation.Examples = {[
Description = "Getting Type Names:",
Code = "{ Type.ToText(3), Type.ToText( {0..4} ), Type.ToText(null) }",
Result = "{ ""Number"", ""List"", ""None""}"
]}
],
Type.ToText_impl = (typeInfo as any, optional options as nullable record) as text =>
let
options = Record.Combine([], options),
name =
if typeInfo is null then "Null"
else if typeInfo is type then "Type"
else if typeInfo is binary then "Binary"
else if typeInfo is number then "Number"
else if typeInfo is function then "Function"
else if typeInfo is list then "List"
else if typeInfo is table then "Table"
else if typeInfo is record then "Record"
else "Other" meta [ ValueType = typeInfo ]
in
name,
Type.ToText = Value.ReplaceType( Type.ToText_impl, Type.ToText.Type )
in
Type.ToText