@@ -58,7 +58,7 @@ const MAX_LONG = 9007199254740991
58
58
const MIN_LONG = - 9007199254740992
59
59
60
60
/**
61
- * verify that a variable contains a safe int (2^31)
61
+ * Verify that a variable contains a safe int (2^31)
62
62
*/
63
63
export function isSafeInteger ( n : unknown ) : boolean {
64
64
return (
@@ -71,9 +71,8 @@ export function isSafeInteger(n: unknown): boolean {
71
71
}
72
72
73
73
/**
74
- * verify that a variable contains a safe long (2^53)
74
+ * Verify that a variable contains a safe long (2^53)
75
75
*/
76
-
77
76
export function isSafeLong ( n : unknown ) : boolean {
78
77
return (
79
78
typeof n === 'number' &&
@@ -85,17 +84,15 @@ export function isSafeLong(n: unknown): boolean {
85
84
}
86
85
87
86
/**
88
- *
87
+ * Check if a number is a safe floating point
89
88
*/
90
-
91
89
export function isSafeFloat ( n : unknown ) : boolean {
92
90
return typeof n === 'number' && n % 0.5 !== 0
93
91
}
94
92
95
93
/**
96
- * convert a date and/or date-time string into a date object
94
+ * Convert a date and/or date-time string into a date object
97
95
*/
98
-
99
96
function toDate ( n : string ) {
100
97
const parsed = Date . parse ( n )
101
98
const $ref = new Date ( )
@@ -113,29 +110,27 @@ function toDate(n: string) {
113
110
}
114
111
115
112
/**
116
- * serialize a date string into the ISO format
113
+ * Serialize a date string into the ISO format
117
114
*/
118
-
119
115
export function serializeDate ( n : string ) {
120
116
const date = toDate ( n )
121
117
return date && date . toJSON ( )
122
118
}
123
119
124
120
/**
125
- * verify that a vriable contains a safe date/date-time string
121
+ * Verify that a vriable contains a safe date/date-time string
126
122
*/
127
-
128
123
export function isSafeDate ( n : string ) : boolean {
129
124
const date = toDate ( n )
130
125
return date !== null && date . getTime ( ) !== NaN
131
126
}
132
127
133
128
/**
134
- * verify is a string is a valid URL
129
+ * Verify is a string is a valid URL
135
130
*/
136
-
137
131
export function isURL ( s : string ) : boolean {
138
132
let res = null
133
+ /* See: https://mathiasbynens.be/demo/url-regex for URL Reg Exp source */
139
134
const urlRegex = / ( h t t p ( s ) ? : \/ \/ .) ? ( w w w \. ) ? [ - a - z A - Z 0 - 9 @ : % . _ \+ ~ # = ] { 2 , 256 } \. [ a - z 0 - 9 ] { 2 , 6 } \b ( [ - a - z A - Z 0 - 9 @ : % _ \+ . ~ # ? & / / = ] * ) / g
140
135
try {
141
136
res = s . match ( urlRegex )
@@ -146,21 +141,19 @@ export function isURL(s: string): boolean {
146
141
}
147
142
148
143
/**
149
- * verify if a string is a valid EMAIL
150
- * See: https://github.com/Urigo/graphql-scalars/blob/master/src/resolvers/EmailAddress.ts#L4
144
+ * Verify if a string is a valid EMAIL
151
145
*/
152
-
153
146
export function isEmail ( s : string ) : boolean {
147
+ /* See: See: https://github.com/Urigo/graphql-scalars/blob/master/src/resolvers/EmailAddress.ts#L4 for EMAIL Reg Exp source */
154
148
const emailRegex = / ^ [ a - z A - Z 0 - 9 . ! # $ % & ’ * + / = ? ^ _ ` { | } ~ - ] + @ [ a - z A - Z 0 - 9 - ] + (?: \. [ a - z A - Z 0 - 9 - ] + ) * $ /
155
149
return emailRegex . test ( s )
156
150
}
157
151
158
152
/**
159
- * verify if a string is a valid GUID/UUID
160
- * See: https://github.com/Urigo/graphql-scalars/blob/master/src/resolvers/GUID.ts#L4
153
+ * Verify if a string is a valid GUID/UUID
161
154
*/
162
-
163
155
export function isUUIDOrGUID ( s : string ) : boolean {
156
+ /* See: See: https://github.com/Urigo/graphql-scalars/blob/master/src/resolvers/GUID.ts#L4 for UUID Reg Exp source */
164
157
const uuidRegExp = / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 1 - 5 ] [ 0 - 9 a - f ] { 3 } - [ 8 9 a b ] [ 0 - 9 a - f ] { 3 } - [ 0 - 9 a - f ] { 12 } $ / i
165
158
const guidRegExp = / ^ ( \{ ) { 0 , 1 } [ 0 - 9 a - f A - F ] { 8 } \- [ 0 - 9 a - f A - F ] { 4 } \- [ 0 - 9 a - f A - F ] { 4 } \- [ 0 - 9 a - f A - F ] { 4 } \- [ 0 - 9 a - f A - F ] { 12 } ( \} ) { 0 , 1 } $ / gi
166
159
@@ -172,9 +165,8 @@ export function isUUIDOrGUID(s: string): boolean {
172
165
}
173
166
174
167
/**
175
- * convert the fist letter of a word in a string to upper case
168
+ * Convert the fist letter of a word in a string to upper case
176
169
*/
177
-
178
170
export function ucFirst ( s : string ) : string {
179
171
if ( typeof s !== 'string' ) {
180
172
return ''
@@ -184,24 +176,24 @@ export function ucFirst(s: string): string {
184
176
}
185
177
186
178
/**
187
- * check if a literal is falsy or not
179
+ * Check if a literal is falsy or not
188
180
*/
189
181
const isLiteralFalsey = ( variable : unknown ) : boolean => {
190
182
return variable === '' || variable === false || variable === 0
191
183
}
192
184
193
185
/**
194
- * check if a variable contains a reference type (not a literal)
186
+ * Check if a variable contains a reference type (not a literal)
195
187
*/
196
-
197
188
const isPrimitive = ( arg : any ) : boolean => {
198
189
return (
199
190
typeof arg === 'object' || ( Boolean ( arg ) && typeof arg . apply === 'function' )
200
191
)
201
192
}
202
193
203
194
/**
204
- * provide the name of primitive and/or reference types
195
+ * Check that the data type of primitive and/or reference
196
+ * variable mathes the type provided
205
197
*/
206
198
const checkTypeName = ( target : unknown , type : string ) : boolean => {
207
199
let typeName = ''
@@ -224,7 +216,7 @@ const checkTypeName = (target: unknown, type: string): boolean => {
224
216
}
225
217
226
218
/**
227
- * get the correct type of a variable
219
+ * Get the correct type of a variable
228
220
*/
229
221
export function strictTypeOf ( value : unknown , type : string ) : boolean {
230
222
// swagger/OpenAPI 'integer' type is converted
@@ -234,6 +226,8 @@ export function strictTypeOf(value: unknown, type: string): boolean {
234
226
}
235
227
236
228
type = type || ''
229
+ // checks that the data type of the variable
230
+ // matches that that was passed in
237
231
return checkTypeName ( value , type )
238
232
}
239
233
@@ -283,7 +277,7 @@ export function handleWarning({
283
277
}
284
278
285
279
// Code provided by codename- from StackOverflow
286
- // Link : https://stackoverflow.com/a/29622653
280
+ // See : https://stackoverflow.com/a/29622653
287
281
export function sortObject ( o ) {
288
282
return Object . keys ( o )
289
283
. sort ( )
0 commit comments