1 | /*!
|
2 | * A MongoDB inspired ES6 Map() query language. - Copyright (c) 2017 Louis T. (https://lou.ist/)
|
3 | * Licensed under the MIT license https://raw.githubusercontent.com/LouisT/MapQL/master/LICENSE
|
4 | */
|
5 | ;
|
6 | /*
|
7 | * A list of data types used in import/export.
|
8 | */
|
9 | const DataTypes = {
|
10 | // List of primitives.
|
11 | 'Boolean': 0,
|
12 | 'Null': 1,
|
13 | 'Undefined': 2,
|
14 | 'Number': 3,
|
15 | 'String': 4,
|
16 | 'Symbol': 5,
|
17 | 'Object': 6,
|
18 | // List of "extra" data types to handle.
|
19 | 'Array': 7,
|
20 | 'Function': 8,
|
21 | 'Date': 9,
|
22 | 'RegExp': 10,
|
23 | 'Map': 11,
|
24 | 'MapQL': 12,
|
25 | 'Set': 13,
|
26 | 'Buffer': 14, // Node.js API for Uint8Array()
|
27 | 'Uint8Array': 15, // Browser equivalent of Node.js Buffer()
|
28 | },
|
29 | Ints = Object.keys(DataTypes).reduce((obj, key) => Object.assign({}, obj, { [DataTypes[key]]: key }), {});
|
30 |
|
31 | module.exports = {
|
32 | typeToInt: (type = 'undefined') => {
|
33 | try {
|
34 | return type in DataTypes ? DataTypes[type] : type;
|
35 | } catch (error) { return type; }
|
36 | },
|
37 | intToType: (int = 2) => {
|
38 | try {
|
39 | return Ints[int] ? Ints[int] : String(int);
|
40 | } catch (error) { return int; }
|
41 | }
|
42 | };
|