@@ -58,7 +58,7 @@ const MAX_LONG = 9007199254740991
5858const MIN_LONG = - 9007199254740992
5959
6060/**
61- * verify that a variable contains a safe int (2^31)
61+ * Verify that a variable contains a safe int (2^31)
6262 */
6363export function isSafeInteger ( n : unknown ) : boolean {
6464 return (
@@ -71,9 +71,8 @@ export function isSafeInteger(n: unknown): boolean {
7171}
7272
7373/**
74- * verify that a variable contains a safe long (2^53)
74+ * Verify that a variable contains a safe long (2^53)
7575 */
76-
7776export function isSafeLong ( n : unknown ) : boolean {
7877 return (
7978 typeof n === 'number' &&
@@ -85,17 +84,15 @@ export function isSafeLong(n: unknown): boolean {
8584}
8685
8786/**
88- *
87+ * Check if a number is a safe floating point
8988 */
90-
9189export function isSafeFloat ( n : unknown ) : boolean {
9290 return typeof n === 'number' && n % 0.5 !== 0
9391}
9492
9593/**
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
9795 */
98-
9996function toDate ( n : string ) {
10097 const parsed = Date . parse ( n )
10198 const $ref = new Date ( )
@@ -113,29 +110,27 @@ function toDate(n: string) {
113110}
114111
115112/**
116- * serialize a date string into the ISO format
113+ * Serialize a date string into the ISO format
117114 */
118-
119115export function serializeDate ( n : string ) {
120116 const date = toDate ( n )
121117 return date && date . toJSON ( )
122118}
123119
124120/**
125- * verify that a vriable contains a safe date/date-time string
121+ * Verify that a vriable contains a safe date/date-time string
126122 */
127-
128123export function isSafeDate ( n : string ) : boolean {
129124 const date = toDate ( n )
130125 return date !== null && date . getTime ( ) !== NaN
131126}
132127
133128/**
134- * verify is a string is a valid URL
129+ * Verify is a string is a valid URL
135130 */
136-
137131export function isURL ( s : string ) : boolean {
138132 let res = null
133+ /* See: https://mathiasbynens.be/demo/url-regex for URL Reg Exp source */
139134 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
140135 try {
141136 res = s . match ( urlRegex )
@@ -146,21 +141,19 @@ export function isURL(s: string): boolean {
146141}
147142
148143/**
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
151145 */
152-
153146export 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 */
154148 const emailRegex = / ^ [ a - z A - Z 0 - 9 . ! # $ % & ’ * + / = ? ^ _ ` { | } ~ - ] + @ [ a - z A - Z 0 - 9 - ] + (?: \. [ a - z A - Z 0 - 9 - ] + ) * $ /
155149 return emailRegex . test ( s )
156150}
157151
158152/**
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
161154 */
162-
163155export 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 */
164157 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
165158 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
166159
@@ -172,9 +165,8 @@ export function isUUIDOrGUID(s: string): boolean {
172165}
173166
174167/**
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
176169 */
177-
178170export function ucFirst ( s : string ) : string {
179171 if ( typeof s !== 'string' ) {
180172 return ''
@@ -184,24 +176,24 @@ export function ucFirst(s: string): string {
184176}
185177
186178/**
187- * check if a literal is falsy or not
179+ * Check if a literal is falsy or not
188180 */
189181const isLiteralFalsey = ( variable : unknown ) : boolean => {
190182 return variable === '' || variable === false || variable === 0
191183}
192184
193185/**
194- * check if a variable contains a reference type (not a literal)
186+ * Check if a variable contains a reference type (not a literal)
195187 */
196-
197188const isPrimitive = ( arg : any ) : boolean => {
198189 return (
199190 typeof arg === 'object' || ( Boolean ( arg ) && typeof arg . apply === 'function' )
200191 )
201192}
202193
203194/**
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
205197 */
206198const checkTypeName = ( target : unknown , type : string ) : boolean => {
207199 let typeName = ''
@@ -224,7 +216,7 @@ const checkTypeName = (target: unknown, type: string): boolean => {
224216}
225217
226218/**
227- * get the correct type of a variable
219+ * Get the correct type of a variable
228220 */
229221export function strictTypeOf ( value : unknown , type : string ) : boolean {
230222 // swagger/OpenAPI 'integer' type is converted
@@ -234,6 +226,8 @@ export function strictTypeOf(value: unknown, type: string): boolean {
234226 }
235227
236228 type = type || ''
229+ // checks that the data type of the variable
230+ // matches that that was passed in
237231 return checkTypeName ( value , type )
238232}
239233
@@ -283,7 +277,7 @@ export function handleWarning({
283277}
284278
285279// Code provided by codename- from StackOverflow
286- // Link : https://stackoverflow.com/a/29622653
280+ // See : https://stackoverflow.com/a/29622653
287281export function sortObject ( o ) {
288282 return Object . keys ( o )
289283 . sort ( )
0 commit comments