Skip to content

Commit 3bd11a8

Browse files
committed
Respond to PR comments:
* Rename `typeOf()` to `type()` * Avoid use of Array.includes()
1 parent 0b92423 commit 3bd11a8

File tree

16 files changed

+24
-20
lines changed

16 files changed

+24
-20
lines changed

docs/object-functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ __Signature:__`$assert(condition, message)`
6363

6464
If condition is true, the function returns undefined. If the condition is false, an exception is thrown with the message as the message of the exception.
6565

66-
## `$typeOf()`
67-
__Signature:__`$typeOf(value)`
66+
## `$type()`
67+
__Signature:__`$type(value)`
6868

6969
Evaluates the type of `value` and returns one of the following strings:
7070
* `"null"`

src/functions.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ const functions = (() => {
18461846
* @param {*} [value] - the input to which the type will be checked
18471847
* @returns {string} - the type of the input
18481848
*/
1849-
function typeOf(value) {
1849+
function type(value) {
18501850
if (value === undefined) {
18511851
return undefined;
18521852
}
@@ -1859,8 +1859,12 @@ const functions = (() => {
18591859
return 'number';
18601860
}
18611861

1862-
if(['string', 'boolean'].includes(typeof value)) {
1863-
return typeof value;
1862+
if (typeof value === 'string') {
1863+
return 'string';
1864+
}
1865+
1866+
if (typeof value === 'boolean') {
1867+
return 'boolean';
18641868
}
18651869

18661870
if(Array.isArray(value)) {
@@ -2047,7 +2051,7 @@ const functions = (() => {
20472051
formatNumber, formatBase, number, floor, ceil, round, abs, sqrt, power, random,
20482052
boolean, not,
20492053
map, zip, filter, single, foldLeft, sift,
2050-
keys, lookup, append, exists, spread, merge, reverse, each, error, assert, typeOf, sort, shuffle, distinct,
2054+
keys, lookup, append, exists, spread, merge, reverse, each, error, assert, type, sort, shuffle, distinct,
20512055
base64encode, base64decode, encodeUrlComponent, encodeUrl, decodeUrlComponent, decodeUrl
20522056
};
20532057
})();

src/jsonata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@ var jsonata = (function() {
18591859
staticFrame.bind('each', defineFunction(fn.each, '<o-f:a>'));
18601860
staticFrame.bind('error', defineFunction(fn.error, '<s?:x>'));
18611861
staticFrame.bind('assert', defineFunction(fn.assert, '<bs?:x>'));
1862-
staticFrame.bind('typeOf', defineFunction(fn.typeOf, '<x:s>'));
1862+
staticFrame.bind('type', defineFunction(fn.type, '<x:s>'));
18631863
staticFrame.bind('sort', defineFunction(fn.sort, '<af?:a>'));
18641864
staticFrame.bind('shuffle', defineFunction(fn.shuffle, '<a:a>'));
18651865
staticFrame.bind('distinct', defineFunction(fn.distinct, '<x:x>'));

test/test-suite/groups/function-typeOf/case001.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"expr": "($var:= undefined; $typeOf($var))",
2+
"expr": "($var:= undefined; $type($var))",
33
"dataset": "dataset5",
44
"bindings": {},
55
"undefinedResult": true

test/test-suite/groups/function-typeOf/case002.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"expr": "($var:= null; $typeOf($var))",
2+
"expr": "($var:= null; $type($var))",
33
"dataset": "dataset5",
44
"bindings": {},
55
"result": "null"

test/test-suite/groups/function-typeOf/case003.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"expr": "($var:= 123; $typeOf($var))",
2+
"expr": "($var:= 123; $type($var))",
33
"dataset": "dataset5",
44
"bindings": {},
55
"result": "number"

test/test-suite/groups/function-typeOf/case004.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"expr": "($var:= '123'; $typeOf($var))",
2+
"expr": "($var:= '123'; $type($var))",
33
"dataset": "dataset5",
44
"bindings": {},
55
"result": "string"

test/test-suite/groups/function-typeOf/case005.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"expr": "($var:= true; $typeOf($var))",
2+
"expr": "($var:= true; $type($var))",
33
"dataset": "dataset5",
44
"bindings": {},
55
"result": "boolean"

test/test-suite/groups/function-typeOf/case006.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"expr": "($var:= 'true'; $typeOf($var))",
2+
"expr": "($var:= 'true'; $type($var))",
33
"dataset": "dataset5",
44
"bindings": {},
55
"result": "string"

test/test-suite/groups/function-typeOf/case007.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"expr": "($var:= []; $typeOf($var))",
2+
"expr": "($var:= []; $type($var))",
33
"dataset": "dataset5",
44
"bindings": {},
55
"result": "array"

0 commit comments

Comments
 (0)