-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample-passing-module.js
More file actions
138 lines (130 loc) · 3.32 KB
/
Copy pathsample-passing-module.js
File metadata and controls
138 lines (130 loc) · 3.32 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// This is an example of a string helper module
/**
* Returns a word with all letter downcases except the first letter
* @param {string} word - The word to be titleized
* @return {string} The string titlelized
* @example
* titleize('wOaH')
* //=> 'Woah'
* @example
* titleize('w')
* //=> 'W'
*/
export function titleize(word) {
switch (word.length) {
case 0:
return "";
case 1:
return word.toUpperCase();
default:
return word[0].toUpperCase() + word.slice(1, word.length).toLowerCase();
}
}
/**
* Returns fairly unnecessary and uninteresting information about a string
* @param {string} string - The string of disinterest
* @return {object} Useless information
* @example
* stringData(
* 'woah'
* )
* //=> {
* length: 4,
* vowels: 2,
* consonants: 2
* }
*/
export function stringData(string) {
const vowels = string
.toLowerCase()
.split("")
.filter((char) => ["a", "e", "i", "o", "u", "y"].find((v) => char === v))
.length;
return {
vowels,
length: string.length,
consonants: string.length - vowels,
};
}
/**
* Does the same thing as String.prototype.split
* @param {string} string - The string you should be using .split on
* @param {string} delimiter - The arg you would pass to .split
* @return {string[]} The exact same thing .splt would return
* @example
* split('why am i doing this?', ' ')
* //=> [ 'why', 'am', 'i', 'doing', 'this?' ]
*/
export function split(string, delimiter) {
return string.split(delimiter);
}
/**
* @param {number} a
* @param {number} b
* @example add(1, 2)
* //=> 3
* @example add(3, 4)
* //=> 7
* @example add(3, 4)
* //=> 7
*/
export function add(a, b) {
return a + b;
}
/**
* Github Issue: https://github.com/supabase/doctest-js/issues/1
* @param {{[key: string]: string}} obj
* @private
* @returns {string}
*
* @example objectToQueryString({
* param1: 'hello',
* param2: 'world'
* })
* //=> 'param1=hello¶m2=world'
*/
export function objectToQueryString(obj) {
return Object.keys(obj)
.map((param) => `${param}=${obj[param]}`)
.join("&");
}
/**
* Github Issue: https://github.com/supabase/doctest-js/issues/1
* Converts the value of an individual column
* @param {String} columnName The column that you want to convert
* @param {{name: String, type: String}[]} columns All of the columns
* @param {String[]} records The map of string values
* @param {String[]} skipTypes An array of types that should not be converted
*
* @example convertColumn(
* 'age',
* [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}],
* ['Paul', '33'],
* []
* )
* //=> 33
* @example convertColumn(
* 'age',
* [{name: 'first_name', type: 'text'}, {name: 'age', type: 'int4'}],
* ['Paul', '33'],
* ['int4']
* )
* //=> '33'
*/
export const convertColumn = (columnName, columns, records, skipTypes) => {
const column = columns.find((x) => x.name == columnName);
const columnNum = columns.findIndex((x) => x.name == columnName);
if (column && skipTypes.includes(column.type)) {
return noop(records[columnNum]);
} else if (column) return convertCell(column.type, records[columnNum]);
function noop(/** @type {string} */ val) {
return val;
}
/**
* @param {string} _type
* @param {string} val
*/
function convertCell(_type, val) {
return parseInt(val);
}
};