@@ -315,64 +315,170 @@ provide let (>=) = (x: Char, y: Char) => {
315315}
316316
317317/**
318- * Checks if the character is an ASCII digit .
318+ * Utilities for working with ASCII characters .
319319 *
320- * @param char: The character to check
321- * @returns `true` if the character is an ASCII digit or `false` otherwise
322- *
323- * @example assert Char.isAsciiDigit('1')
324- * @example assert !Char.isAsciiDigit('a')
320+ * @example Char.Ascii.isAscii('1')
325321 *
326- * @since v0.6 .0
322+ * @since v0.7 .0
327323 */
328- provide let isAsciiDigit = char => char >= '0' && char <= '9'
324+ provide module Ascii {
325+ /**
326+ * The minimum valid ASCII character code.
327+ *
328+ * @since v0.7.0
329+ */
330+ provide let min = 0x00
329331
330- /**
331- * Checks if the character is an ASCII alphabetical character.
332- *
333- * @param char: The character to check
334- * @returns `true` if the character is an ASCII alphabetical or `false` otherwise
335- *
336- * @example assert Char.isAsciiAlpha('a')
337- * @example assert !Char.isAsciiAlpha('1')
338- *
339- * @since v0.6.0
340- */
341- provide let isAsciiAlpha = char =>
342- char >= 'a' && char <= 'z' || char >= 'A' && char <= 'Z'
332+ /**
333+ * The maximum valid ASCII character code.
334+ *
335+ * @since v0.7.0
336+ */
337+ provide let max = 0x7F
343338
344- /**
345- * Converts the character to ASCII lowercase if it is an ASCII uppercase character.
346- *
347- * @param char: The character to convert
348- * @returns The lowercased character
349- *
350- * @example assert Char.toAsciiLowercase('B') == 'b'
351- *
352- * @since v0.6.0
353- */
354- provide let toAsciiLowercase = char => {
355- if (char >= 'A' && char <= 'Z') {
356- fromCode(code(char) + 0x20)
357- } else {
358- char
339+ /**
340+ * Checks if the character is a valid ASCII character.
341+ *
342+ * @param char: The character to check
343+ * @returns `true` if the character is an ASCII character or `false` otherwise
344+ *
345+ * @example assert Char.Ascii.isValid('1')
346+ * @example assert Char.Ascii.isValid('a')
347+ * @example assert !Char.Ascii.isValid('🌾')
348+ *
349+ * @since v0.7.0
350+ */
351+ provide let isValid = char => char <= '\u{007F}'
352+
353+ /**
354+ * Checks if the character is an ASCII digit.
355+ *
356+ * @param char: The character to check
357+ * @returns `true` if the character is an ASCII digit or `false` otherwise
358+ *
359+ * @example assert Char.Ascii.isDigit('1')
360+ * @example assert !Char.Ascii.isDigit('a')
361+ *
362+ * @since v0.7.0
363+ * @history v0.6.0: Originally `Char.isAsciiDigit`
364+ */
365+ provide let isDigit = char => char >= '0' && char <= '9'
366+
367+ /**
368+ * Checks if the character is an ASCII alphabetical character.
369+ *
370+ * @param char: The character to check
371+ * @returns `true` if the character is an ASCII alphabetical or `false` otherwise
372+ *
373+ * @example assert Char.Ascii.isAlpha('a')
374+ * @example assert !Char.Ascii.isAlpha('1')
375+ *
376+ * @since v0.7.0
377+ * @history v0.6.0: Originally `Char.isAsciiAlpha`
378+ */
379+ provide let isAlpha = char =>
380+ char >= 'a' && char <= 'z' || char >= 'A' && char <= 'Z'
381+
382+ /**
383+ * Checks if the character is an ASCII control character.
384+ *
385+ * @param char: The character to check
386+ * @returns `true` if the character is an ASCII control character or `false` otherwise
387+ *
388+ * @example assert Char.Ascii.isControl('\t')
389+ * @example assert Char.Ascii.isControl('\n')
390+ * @example assert !Char.Ascii.isControl('1')
391+ * @example assert !Char.Ascii.isControl('a')
392+ *
393+ * @since v0.7.0
394+ */
395+ provide let isControl = char => char <= '\u{001F}' || char == '\u{007F}'
396+
397+ /**
398+ * Checks if the character is an ASCII whitespace character.
399+ *
400+ * @param char: The character to check
401+ * @returns `true` if the character is an ASCII whitespace character or `false` otherwise
402+ *
403+ * @example assert Char.isWhitespace('\t')
404+ * @example assert Char.isWhitespace('\n')
405+ * @example assert !Char.isWhitespace('1')
406+ * @example assert !Char.isWhitespace('a')
407+ *
408+ * @since v0.7.0
409+ */
410+ provide let isWhitespace = char => {
411+ match (char) {
412+ '\t' | '\n' | '\x0C' | '\r' | ' ' => true,
413+ _ => false,
414+ }
359415 }
360- }
361416
362- /**
363- * Converts the character to ASCII uppercase if it is an ASCII lowercase character.
364- *
365- * @param char: The character to convert
366- * @returns The uppercased character
367- *
368- * @example assert Char.toAsciiUppercase('b') == 'B'
369- *
370- * @since v0.6.0
371- */
372- provide let toAsciiUppercase = char => {
373- if (char >= 'a' && char <= 'z') {
374- fromCode(code(char) - 0x20)
375- } else {
376- char
417+ /**
418+ * Checks if the character is an ASCII punctuation character.
419+ *
420+ * @param char: The character to check
421+ * @returns `true` if the character is an ASCII punctuation character or `false` otherwise
422+ *
423+ * @example assert Char.Ascii.isPunctuation('!')
424+ * @example assert !Char.Ascii.isPunctuation('1')
425+ *
426+ * @since v0.7.0
427+ */
428+ provide let isPunctuation = char =>
429+ char >= '!' && char <= '/' ||
430+ char >= ':' && char <= '@' ||
431+ char >= '[' && char <= '`' ||
432+ char >= '{' && char <= '~'
433+
434+ /**
435+ * Checks if the character is an ASCII graphic character.
436+ *
437+ * @param char: The character to check
438+ * @returns `true` if the character is an ASCII graphic character or `false` otherwise
439+ *
440+ * @example assert Char.Ascii.isGraphic('!')
441+ * @example assert !Char.Ascii.isGraphic('\t')
442+ *
443+ * @since v0.7.0
444+ */
445+ provide let isGraphic = char => char >= '!' && char <= '~'
446+
447+ /**
448+ * Converts the character to ASCII lowercase if it is an ASCII uppercase character.
449+ *
450+ * @param char: The character to convert
451+ * @returns The lowercased character
452+ *
453+ * @example assert Char.Ascii.toLowercase('B') == 'b'
454+ *
455+ * @since v0.7.0
456+ * @history v0.6.0: Originally `Char.toAsciiLowercase`
457+ */
458+ provide let toLowercase = char => {
459+ if (char >= 'A' && char <= 'Z') {
460+ fromCode(code(char) + 0x20)
461+ } else {
462+ char
463+ }
464+ }
465+
466+ /**
467+ * Converts the character to ASCII uppercase if it is an ASCII lowercase character.
468+ *
469+ * @param char: The character to convert
470+ * @returns The uppercased character
471+ *
472+ * @example assert Char.Ascii.toUppercase('b') == 'B'
473+ *
474+ * @since v0.7.0
475+ * @history v0.6.0: Originally `Char.toAsciiUppercase`
476+ */
477+ provide let toUppercase = char => {
478+ if (char >= 'a' && char <= 'z') {
479+ fromCode(code(char) - 0x20)
480+ } else {
481+ char
482+ }
377483 }
378484}
0 commit comments