stringzy 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/.github/workflows/auto-assign.yml +26 -0
  2. package/CODE_OF_CONDUCT.MD +115 -0
  3. package/README.md +963 -40
  4. package/dist/analyzing/checkMultiplePatterns.d.ts +14 -0
  5. package/dist/analyzing/checkMultiplePatterns.js +75 -0
  6. package/dist/analyzing/checkSubsequence.d.ts +14 -0
  7. package/dist/analyzing/checkSubsequence.js +33 -0
  8. package/dist/analyzing/contentWordCount.d.ts +11 -0
  9. package/dist/analyzing/contentWordCount.js +23 -0
  10. package/dist/analyzing/functionWordCount.d.ts +11 -0
  11. package/dist/analyzing/functionWordCount.js +33 -0
  12. package/dist/analyzing/index.d.ts +14 -0
  13. package/dist/analyzing/index.js +22 -2
  14. package/dist/analyzing/lexicographicalRank.d.ts +26 -0
  15. package/dist/analyzing/lexicographicalRank.js +66 -0
  16. package/dist/analyzing/patternCount.d.ts +6 -5
  17. package/dist/analyzing/patternCount.js +19 -17
  18. package/dist/analyzing/stringRotation.d.ts +29 -0
  19. package/dist/analyzing/stringRotation.js +44 -0
  20. package/dist/formatting/binary.d.ts +24 -0
  21. package/dist/formatting/binary.js +49 -0
  22. package/dist/formatting/creditCard.d.ts +8 -0
  23. package/dist/formatting/creditCard.js +28 -0
  24. package/dist/formatting/decimal.d.ts +21 -0
  25. package/dist/formatting/decimal.js +73 -0
  26. package/dist/formatting/duration.d.ts +27 -0
  27. package/dist/formatting/duration.js +92 -0
  28. package/dist/formatting/fileSize.d.ts +18 -0
  29. package/dist/formatting/fileSize.js +39 -0
  30. package/dist/formatting/hexadecimal.d.ts +14 -0
  31. package/dist/formatting/hexadecimal.js +38 -0
  32. package/dist/formatting/index.d.ts +42 -0
  33. package/dist/formatting/index.js +57 -1
  34. package/dist/formatting/listToString.d.ts +17 -0
  35. package/dist/formatting/listToString.js +35 -0
  36. package/dist/formatting/octal.d.ts +19 -0
  37. package/dist/formatting/octal.js +31 -0
  38. package/dist/formatting/ordinal.d.ts +20 -0
  39. package/dist/formatting/ordinal.js +43 -0
  40. package/dist/formatting/percentage.d.ts +19 -0
  41. package/dist/formatting/percentage.js +31 -0
  42. package/dist/formatting/romanNumerals.d.ts +20 -0
  43. package/dist/formatting/romanNumerals.js +53 -0
  44. package/dist/formatting/scientific.d.ts +14 -0
  45. package/dist/formatting/scientific.js +24 -0
  46. package/dist/formatting/temperature.d.ts +6 -0
  47. package/dist/formatting/temperature.js +27 -0
  48. package/dist/formatting/trim.d.ts +10 -0
  49. package/dist/formatting/trim.js +20 -0
  50. package/dist/index.d.ts +30 -0
  51. package/dist/tests/analyzing/checkMultiplePatterns.test.d.ts +1 -0
  52. package/dist/tests/analyzing/checkMultiplePatterns.test.js +81 -0
  53. package/dist/tests/analyzing/checkSubsequence.test.d.ts +1 -0
  54. package/dist/tests/analyzing/checkSubsequence.test.js +34 -0
  55. package/dist/tests/analyzing/contentWordCount.test.d.ts +1 -0
  56. package/dist/tests/analyzing/contentWordCount.test.js +20 -0
  57. package/dist/tests/analyzing/functionWordCount.test.d.ts +1 -0
  58. package/dist/tests/analyzing/functionWordCount.test.js +20 -0
  59. package/dist/tests/analyzing/lexicographicalRank.test.d.ts +1 -0
  60. package/dist/tests/analyzing/lexicographicalRank.test.js +43 -0
  61. package/dist/tests/analyzing/stringRotation.test.d.ts +1 -0
  62. package/dist/tests/analyzing/stringRotation.test.js +42 -0
  63. package/dist/tests/formatting/binary.test.d.ts +1 -0
  64. package/dist/tests/formatting/binary.test.js +53 -0
  65. package/dist/tests/formatting/creditCard.test.d.ts +1 -0
  66. package/dist/tests/formatting/creditCard.test.js +31 -0
  67. package/dist/tests/formatting/decimal.test.d.ts +1 -0
  68. package/dist/tests/formatting/decimal.test.js +62 -0
  69. package/dist/tests/formatting/duration.test.d.ts +1 -0
  70. package/dist/tests/formatting/duration.test.js +61 -0
  71. package/dist/tests/formatting/fileSize.test.d.ts +1 -0
  72. package/dist/tests/formatting/fileSize.test.js +39 -0
  73. package/dist/tests/formatting/hexadecimal.test.d.ts +1 -0
  74. package/dist/tests/formatting/hexadecimal.test.js +38 -0
  75. package/dist/tests/formatting/listToString.test.d.ts +1 -0
  76. package/dist/tests/formatting/listToString.test.js +37 -0
  77. package/dist/tests/formatting/octal.test.d.ts +1 -0
  78. package/dist/tests/formatting/octal.test.js +36 -0
  79. package/dist/tests/formatting/ordinal.test.d.ts +1 -0
  80. package/dist/tests/formatting/ordinal.test.js +37 -0
  81. package/dist/tests/formatting/percentage.test.d.ts +1 -0
  82. package/dist/tests/formatting/percentage.test.js +38 -0
  83. package/dist/tests/formatting/romanNumerals.test.d.ts +1 -0
  84. package/dist/tests/formatting/romanNumerals.test.js +35 -0
  85. package/dist/tests/formatting/scientific.test.d.ts +1 -0
  86. package/dist/tests/formatting/scientific.test.js +35 -0
  87. package/dist/tests/formatting/temperature.test.d.ts +1 -0
  88. package/dist/tests/formatting/temperature.test.js +34 -0
  89. package/dist/tests/formatting/trim.test.d.ts +1 -0
  90. package/dist/tests/formatting/trim.test.js +42 -0
  91. package/dist/tests/transformations/reverseString.test.d.ts +1 -0
  92. package/dist/tests/transformations/reverseString.test.js +41 -0
  93. package/dist/tests/transformations/stringCombinations.test.d.ts +1 -0
  94. package/dist/tests/transformations/stringCombinations.test.js +41 -0
  95. package/dist/tests/transformations/stringPermutations.test.d.ts +1 -0
  96. package/dist/tests/transformations/stringPermutations.test.js +110 -0
  97. package/dist/tests/validations/isAlphaNumeric.test.d.ts +1 -0
  98. package/dist/tests/validations/isAlphaNumeric.test.js +30 -0
  99. package/dist/tests/validations/isAlphabetic.test.d.ts +1 -0
  100. package/dist/tests/validations/isAlphabetic.test.js +32 -0
  101. package/dist/tests/validations/isAnagram.test.d.ts +1 -0
  102. package/dist/tests/validations/isAnagram.test.js +44 -0
  103. package/dist/tests/validations/isIPv6.test.d.ts +1 -0
  104. package/dist/tests/validations/isIPv6.test.js +65 -0
  105. package/dist/tests/validations/isLowerCase.test.d.ts +1 -0
  106. package/dist/tests/validations/isLowerCase.test.js +50 -0
  107. package/dist/tests/validations/isMacAddress.test.d.ts +1 -0
  108. package/dist/tests/validations/isMacAddress.test.js +72 -0
  109. package/dist/tests/validations/isPanagram.test.d.ts +1 -0
  110. package/dist/tests/validations/isPanagram.test.js +39 -0
  111. package/dist/tests/validations/isUpperCase.test.d.ts +1 -0
  112. package/dist/tests/validations/isUpperCase.test.js +50 -0
  113. package/dist/transformations/index.d.ts +10 -0
  114. package/dist/transformations/index.js +16 -2
  115. package/dist/transformations/reverseWordsInString .d.ts +9 -0
  116. package/dist/transformations/reverseWordsInString .js +49 -0
  117. package/dist/transformations/stringCombinations.d.ts +28 -0
  118. package/dist/transformations/stringCombinations.js +44 -0
  119. package/dist/transformations/stringPermutations.d.ts +53 -0
  120. package/dist/transformations/stringPermutations.js +179 -0
  121. package/dist/validations/index.d.ts +24 -0
  122. package/dist/validations/index.js +34 -2
  123. package/dist/validations/isAlphaNumeric.d.ts +11 -0
  124. package/dist/validations/isAlphaNumeric.js +22 -0
  125. package/dist/validations/isAlphabetic.d.ts +9 -0
  126. package/dist/validations/isAlphabetic.js +21 -0
  127. package/dist/validations/isAnagram.d.ts +13 -0
  128. package/dist/validations/isAnagram.js +23 -0
  129. package/dist/validations/isIPv6.d.ts +24 -0
  130. package/dist/validations/isIPv6.js +45 -0
  131. package/dist/validations/isLowerCase.d.ts +12 -0
  132. package/dist/validations/isLowerCase.js +32 -0
  133. package/dist/validations/isMacAddress.d.ts +27 -0
  134. package/dist/validations/isMacAddress.js +43 -0
  135. package/dist/validations/isPanagram.d.ts +20 -0
  136. package/dist/validations/isPanagram.js +35 -0
  137. package/dist/validations/isUpperCase.d.ts +12 -0
  138. package/dist/validations/isUpperCase.js +32 -0
  139. package/package.json +3 -3
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatCreditCard = formatCreditCard;
4
+ /**
5
+ * Formats a credit card number by grouping digits into readable parts.
6
+ *
7
+ * @param {string} cardNumber - The credit card number to format.
8
+ * @returns {string} The formatted credit card number.
9
+ * @throws {TypeError} If the input is not a string.
10
+ */
11
+ function formatCreditCard(cardNumber) {
12
+ if (typeof cardNumber !== 'string') {
13
+ throw new TypeError('Input must be a string');
14
+ }
15
+ // Remove all non-digit characters
16
+ const cleaned = cardNumber.replace(/\D/g, '');
17
+ // Only accept 15 or 16 digit card numbers
18
+ if (cleaned.length !== 15 && cleaned.length !== 16) {
19
+ return '';
20
+ }
21
+ // Format based on length:
22
+ // 16 digits → 4-4-4-4 (Visa, MasterCard)
23
+ if (cleaned.length === 16) {
24
+ return cleaned.replace(/(\d{4})(?=\d)/g, '$1 ').trim();
25
+ }
26
+ // 15 digits → 4-6-5 (AmEx)
27
+ return cleaned.replace(/(\d{4})(\d{6})(\d{5})/, '$1 $2 $3');
28
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Converts a string in base 2, 8, or 16 to its decimal (base-10) number.
3
+ *
4
+ * - Supports optional standard prefixes: 0b, 0o, 0x (case-insensitive)
5
+ * - Trims leading/trailing whitespace
6
+ * - Supports uppercase and lowercase characters for hexadecimal
7
+ *
8
+ * Examples:
9
+ * formatToDecimal('1010', { base: 2 }) → 10
10
+ * formatToDecimal('12', { base: 8 }) → 10
11
+ * formatToDecimal('FF', { base: 16 }) → 255
12
+ * formatToDecimal('0xFF', { base: 16 })→ 255
13
+ *
14
+ * @param {string} value - The input string representing a number in the given base.
15
+ * @param {{ base: 2 | 8 | 16 }} options - Options containing the base of the input string.
16
+ * @returns {number} The decimal (base-10) representation.
17
+ * @throws {TypeError} For non-string inputs, unsupported bases, or malformed values.
18
+ */
19
+ export declare function formatToDecimal(value: string, options: {
20
+ base: 2 | 8 | 16;
21
+ }): number;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatToDecimal = formatToDecimal;
4
+ /**
5
+ * Converts a string in base 2, 8, or 16 to its decimal (base-10) number.
6
+ *
7
+ * - Supports optional standard prefixes: 0b, 0o, 0x (case-insensitive)
8
+ * - Trims leading/trailing whitespace
9
+ * - Supports uppercase and lowercase characters for hexadecimal
10
+ *
11
+ * Examples:
12
+ * formatToDecimal('1010', { base: 2 }) → 10
13
+ * formatToDecimal('12', { base: 8 }) → 10
14
+ * formatToDecimal('FF', { base: 16 }) → 255
15
+ * formatToDecimal('0xFF', { base: 16 })→ 255
16
+ *
17
+ * @param {string} value - The input string representing a number in the given base.
18
+ * @param {{ base: 2 | 8 | 16 }} options - Options containing the base of the input string.
19
+ * @returns {number} The decimal (base-10) representation.
20
+ * @throws {TypeError} For non-string inputs, unsupported bases, or malformed values.
21
+ */
22
+ function formatToDecimal(value, options) {
23
+ if (typeof value !== 'string') {
24
+ throw new TypeError('Input must be a string');
25
+ }
26
+ const base = options === null || options === void 0 ? void 0 : options.base;
27
+ if (base !== 2 && base !== 8 && base !== 16) {
28
+ throw new TypeError('Base must be one of 2, 8, or 16');
29
+ }
30
+ let trimmed = value.trim();
31
+ if (trimmed.length === 0) {
32
+ throw new TypeError('Input must be a non-empty string');
33
+ }
34
+ // Optional sign support; not required by spec but harmless and intuitive
35
+ let isNegative = false;
36
+ if (trimmed.startsWith('+') || trimmed.startsWith('-')) {
37
+ isNegative = trimmed[0] === '-';
38
+ trimmed = trimmed.slice(1);
39
+ if (trimmed.length === 0) {
40
+ throw new TypeError('Malformed numeric string');
41
+ }
42
+ }
43
+ // Strip standard prefixes if present and base matches
44
+ const prefix = trimmed.slice(0, 2).toLowerCase();
45
+ if (prefix === '0b' && base === 2) {
46
+ trimmed = trimmed.slice(2);
47
+ }
48
+ else if (prefix === '0o' && base === 8) {
49
+ trimmed = trimmed.slice(2);
50
+ }
51
+ else if (prefix === '0x' && base === 16) {
52
+ trimmed = trimmed.slice(2);
53
+ }
54
+ if (trimmed.length === 0) {
55
+ throw new TypeError('Malformed numeric string');
56
+ }
57
+ // Validate characters for the specified base
58
+ let pattern;
59
+ if (base === 2) {
60
+ pattern = /^[01]+$/;
61
+ }
62
+ else if (base === 8) {
63
+ pattern = /^[0-7]+$/;
64
+ }
65
+ else {
66
+ pattern = /^[0-9a-fA-F]+$/;
67
+ }
68
+ if (!pattern.test(trimmed)) {
69
+ throw new TypeError('Input contains invalid characters for the specified base');
70
+ }
71
+ const parsed = parseInt(trimmed, base);
72
+ return isNegative ? -parsed : parsed;
73
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Converts a duration in seconds or milliseconds into a human-readable string.
3
+ * Intelligently displays hours, minutes, seconds, and optionally milliseconds,
4
+ * while skipping zero-value units unless the entire duration is zero.
5
+ *
6
+ * @param {number} input - The duration in seconds or milliseconds.
7
+ * @param {object} [options] - Configuration options.
8
+ * @param {string} [options.unit='seconds'] - The input unit: 'seconds' or 'milliseconds'.
9
+ * @param {string} [options.format='short'] - Output format: 'short', 'medium', or 'long'.
10
+ * @param {boolean} [options.includeMs=false] - Whether to include milliseconds in the output.
11
+ * @param {string} [options.delimiter=' '] - The delimiter between time units.
12
+ * @returns {string} The formatted duration string.
13
+ * @throws {TypeError} If input is not a number or is negative.
14
+ *
15
+ * @example
16
+ * formatDuration(60); // "1m"
17
+ * formatDuration(61); // "1m 1s"
18
+ * formatDuration(3661); // "1h 1m 1s"
19
+ * formatDuration(1234567, { unit: 'milliseconds', includeMs: true }); // "20m 34s 567ms"
20
+ * formatDuration(3600, { format: 'long' }); // "1 hour"
21
+ */
22
+ export declare function formatDuration(input: number, options?: {
23
+ unit?: 'seconds' | 'milliseconds';
24
+ format?: 'short' | 'medium' | 'long';
25
+ includeMs?: boolean;
26
+ delimiter?: string;
27
+ }): string;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatDuration = formatDuration;
4
+ /**
5
+ * Converts a duration in seconds or milliseconds into a human-readable string.
6
+ * Intelligently displays hours, minutes, seconds, and optionally milliseconds,
7
+ * while skipping zero-value units unless the entire duration is zero.
8
+ *
9
+ * @param {number} input - The duration in seconds or milliseconds.
10
+ * @param {object} [options] - Configuration options.
11
+ * @param {string} [options.unit='seconds'] - The input unit: 'seconds' or 'milliseconds'.
12
+ * @param {string} [options.format='short'] - Output format: 'short', 'medium', or 'long'.
13
+ * @param {boolean} [options.includeMs=false] - Whether to include milliseconds in the output.
14
+ * @param {string} [options.delimiter=' '] - The delimiter between time units.
15
+ * @returns {string} The formatted duration string.
16
+ * @throws {TypeError} If input is not a number or is negative.
17
+ *
18
+ * @example
19
+ * formatDuration(60); // "1m"
20
+ * formatDuration(61); // "1m 1s"
21
+ * formatDuration(3661); // "1h 1m 1s"
22
+ * formatDuration(1234567, { unit: 'milliseconds', includeMs: true }); // "20m 34s 567ms"
23
+ * formatDuration(3600, { format: 'long' }); // "1 hour"
24
+ */
25
+ function formatDuration(input, options) {
26
+ // Validate input
27
+ if (typeof input !== 'number' || isNaN(input)) {
28
+ throw new TypeError('Input must be a number');
29
+ }
30
+ if (input < 0) {
31
+ throw new TypeError('Input must be non-negative');
32
+ }
33
+ // Default options
34
+ const opts = {
35
+ unit: (options === null || options === void 0 ? void 0 : options.unit) || 'seconds',
36
+ format: (options === null || options === void 0 ? void 0 : options.format) || 'short',
37
+ includeMs: (options === null || options === void 0 ? void 0 : options.includeMs) || false,
38
+ delimiter: (options === null || options === void 0 ? void 0 : options.delimiter) || ' '
39
+ };
40
+ // Convert to milliseconds
41
+ const totalMs = opts.unit === 'seconds' ? input * 1000 : input;
42
+ // Handle zero case
43
+ if (totalMs === 0) {
44
+ return '0s';
45
+ }
46
+ // Calculate time components
47
+ let remaining = Math.floor(totalMs);
48
+ const ms = remaining % 1000;
49
+ remaining = Math.floor(remaining / 1000);
50
+ const seconds = remaining % 60;
51
+ remaining = Math.floor(remaining / 60);
52
+ const minutes = remaining % 60;
53
+ const hours = Math.floor(remaining / 60);
54
+ // Build the output parts
55
+ const parts = [];
56
+ // Add non-zero units
57
+ if (hours > 0) {
58
+ parts.push(formatTimeUnit(hours, 'h', opts.format));
59
+ }
60
+ if (minutes > 0) {
61
+ parts.push(formatTimeUnit(minutes, 'm', opts.format));
62
+ }
63
+ if (seconds > 0 || (parts.length === 0 && !opts.includeMs)) {
64
+ parts.push(formatTimeUnit(seconds, 's', opts.format));
65
+ }
66
+ if (opts.includeMs && ms > 0) {
67
+ parts.push(formatTimeUnit(ms, 'ms', opts.format));
68
+ }
69
+ return parts.join(opts.delimiter);
70
+ }
71
+ /**
72
+ * Formats a single time unit according to the specified format.
73
+ * @private
74
+ */
75
+ function formatTimeUnit(value, unit, format) {
76
+ switch (format) {
77
+ case 'long':
78
+ const unitNames = {
79
+ 'h': ['hour', 'hours'],
80
+ 'm': ['minute', 'minutes'],
81
+ 's': ['second', 'seconds'],
82
+ 'ms': ['millisecond', 'milliseconds']
83
+ };
84
+ const [singular, plural] = unitNames[unit];
85
+ return `${value} ${value === 1 ? singular : plural}`;
86
+ case 'medium':
87
+ const paddedValue = unit === 'h' ? value : value.toString().padStart(2, '0');
88
+ return `${paddedValue}${unit}`;
89
+ default: // 'short'
90
+ return `${value}${unit}`;
91
+ }
92
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Converts a number of bytes into a human-readable file size string (B, KB, MB, GB, TB).
3
+ *
4
+ * Supports values from bytes up to terabytes, with automatic unit scaling and correct rounding.
5
+ *
6
+ * Examples:
7
+ * 123 → "123 B"
8
+ * 1024 → "1 KB"
9
+ * 1048576 → "1 MB"
10
+ * 1073741824 → "1 GB"
11
+ * 1572864 → "1.5 MB"
12
+ *
13
+ * @param {number} bytes - The number of bytes to convert.
14
+ * @param {number} [precision=2] - The number of decimal places to include for non-integer conversions.
15
+ * @returns {string} The formatted file size string with units.
16
+ * @throws {TypeError} If the input is not a number or precision is not a valid number.
17
+ */
18
+ export declare function formatFileSize(bytes: number, precision?: number): string;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatFileSize = formatFileSize;
4
+ /**
5
+ * Converts a number of bytes into a human-readable file size string (B, KB, MB, GB, TB).
6
+ *
7
+ * Supports values from bytes up to terabytes, with automatic unit scaling and correct rounding.
8
+ *
9
+ * Examples:
10
+ * 123 → "123 B"
11
+ * 1024 → "1 KB"
12
+ * 1048576 → "1 MB"
13
+ * 1073741824 → "1 GB"
14
+ * 1572864 → "1.5 MB"
15
+ *
16
+ * @param {number} bytes - The number of bytes to convert.
17
+ * @param {number} [precision=2] - The number of decimal places to include for non-integer conversions.
18
+ * @returns {string} The formatted file size string with units.
19
+ * @throws {TypeError} If the input is not a number or precision is not a valid number.
20
+ */
21
+ function formatFileSize(bytes, precision = 2) {
22
+ if (typeof bytes !== 'number' || Number.isNaN(bytes)) {
23
+ throw new TypeError('Input must be a number');
24
+ }
25
+ if (typeof precision !== 'number' || Number.isNaN(precision) || precision < 0) {
26
+ throw new TypeError('Precision must be a non-negative number');
27
+ }
28
+ if (bytes < 0) {
29
+ throw new RangeError('File size cannot be negative');
30
+ }
31
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
32
+ if (bytes === 0)
33
+ return `0 B`;
34
+ const i = Math.floor(Math.log(bytes) / Math.log(1024));
35
+ const value = bytes / Math.pow(1024, i);
36
+ // ✅ Fix: trim trailing zeros by converting to number before string
37
+ const rounded = value % 1 === 0 ? value.toString() : parseFloat(value.toFixed(precision)).toString();
38
+ return `${rounded} ${units[i]}`;
39
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Converts a decimal number to its hexadecimal (base-16) representation.
3
+ *
4
+ * @param {number} num - The decimal number to convert.
5
+ * @param {object} [options] - Optional formatting options.
6
+ * @param {boolean} [options.prefix=false] - Whether to add "0x" before the result.
7
+ * @param {boolean} [options.lowercase=false] - Whether to return hexadecimal in lowercase.
8
+ * @returns {string} The hexadecimal representation of the number.
9
+ * @throws {TypeError} If the input is not a valid number.
10
+ */
11
+ export declare function formatToHexadecimal(num: number, options?: {
12
+ prefix?: boolean;
13
+ lowercase?: boolean;
14
+ }): string;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatToHexadecimal = formatToHexadecimal;
4
+ /**
5
+ * Converts a decimal number to its hexadecimal (base-16) representation.
6
+ *
7
+ * @param {number} num - The decimal number to convert.
8
+ * @param {object} [options] - Optional formatting options.
9
+ * @param {boolean} [options.prefix=false] - Whether to add "0x" before the result.
10
+ * @param {boolean} [options.lowercase=false] - Whether to return hexadecimal in lowercase.
11
+ * @returns {string} The hexadecimal representation of the number.
12
+ * @throws {TypeError} If the input is not a valid number.
13
+ */
14
+ function formatToHexadecimal(num, options) {
15
+ if (typeof num !== 'number' || isNaN(num)) {
16
+ throw new TypeError('Input must be a valid number');
17
+ }
18
+ const { prefix = false, lowercase = false } = options || {};
19
+ // Convert number to hexadecimal (absolute value first to handle negatives)
20
+ let hex = Math.abs(num).toString(16).toUpperCase();
21
+ if (lowercase) {
22
+ hex = hex.toLowerCase();
23
+ }
24
+ // Add negative sign if original number was negative
25
+ if (num < 0) {
26
+ hex = '-' + hex;
27
+ }
28
+ // Add prefix (0x or -0x) if enabled
29
+ if (prefix) {
30
+ if (hex.startsWith('-')) {
31
+ hex = '-0x' + hex.slice(1);
32
+ }
33
+ else {
34
+ hex = '0x' + hex;
35
+ }
36
+ }
37
+ return hex;
38
+ }
@@ -1,11 +1,53 @@
1
1
  export { capitalize } from './capitalize';
2
2
  export { formatNumber } from './number';
3
3
  export { formatPhone } from './phone';
4
+ export { formatDuration } from './duration';
5
+ export { trim } from './trim';
6
+ export { formatRomanNumeral } from './romanNumerals';
7
+ export { formatPercentage } from './percentage';
8
+ export { formatFileSize } from './fileSize';
9
+ export { formatOrdinal } from './ordinal';
10
+ export { formatList } from './listToString';
11
+ export { formatCreditCard } from './creditCard';
12
+ export { formatToOctal } from './octal';
13
+ export { formatTemperature } from './temperature';
14
+ export { formatScientific } from './scientific';
15
+ export { formatToBinary } from './binary';
16
+ export { formatToHexadecimal } from './hexadecimal';
17
+ export { formatToDecimal } from './decimal';
4
18
  import { capitalize } from './capitalize';
5
19
  import { formatNumber } from './number';
6
20
  import { formatPhone } from './phone';
21
+ import { formatDuration } from './duration';
22
+ import { trim } from './trim';
23
+ import { formatRomanNumeral } from './romanNumerals';
24
+ import { formatPercentage } from './percentage';
25
+ import { formatFileSize } from './fileSize';
26
+ import { formatOrdinal } from './ordinal';
27
+ import { formatList } from './listToString';
28
+ import { formatCreditCard } from './creditCard';
29
+ import { formatToOctal } from './octal';
30
+ import { formatTemperature } from './temperature';
31
+ import { formatScientific } from './scientific';
32
+ import { formatToBinary } from './binary';
33
+ import { formatToHexadecimal } from './hexadecimal';
34
+ import { formatToDecimal } from './decimal';
7
35
  export declare const formatting: {
8
36
  capitalize: typeof capitalize;
9
37
  formatNumber: typeof formatNumber;
10
38
  formatPhone: typeof formatPhone;
39
+ formatDuration: typeof formatDuration;
40
+ trim: typeof trim;
41
+ formatRomanNumeral: typeof formatRomanNumeral;
42
+ formatPercentage: typeof formatPercentage;
43
+ formatFileSize: typeof formatFileSize;
44
+ formatOrdinal: typeof formatOrdinal;
45
+ formatList: typeof formatList;
46
+ formatTemperature: typeof formatTemperature;
47
+ formatScientific: typeof formatScientific;
48
+ formatCreditCard: typeof formatCreditCard;
49
+ formatToBinary: typeof formatToBinary;
50
+ formatToHexadecimal: typeof formatToHexadecimal;
51
+ formatToOctal: typeof formatToOctal;
52
+ formatToDecimal: typeof formatToDecimal;
11
53
  };
@@ -1,17 +1,73 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatting = exports.formatPhone = exports.formatNumber = exports.capitalize = void 0;
3
+ exports.formatting = exports.formatToDecimal = exports.formatToHexadecimal = exports.formatToBinary = exports.formatScientific = exports.formatTemperature = exports.formatToOctal = exports.formatCreditCard = exports.formatList = exports.formatOrdinal = exports.formatFileSize = exports.formatPercentage = exports.formatRomanNumeral = exports.trim = exports.formatDuration = exports.formatPhone = exports.formatNumber = exports.capitalize = void 0;
4
4
  var capitalize_1 = require("./capitalize");
5
5
  Object.defineProperty(exports, "capitalize", { enumerable: true, get: function () { return capitalize_1.capitalize; } });
6
6
  var number_1 = require("./number");
7
7
  Object.defineProperty(exports, "formatNumber", { enumerable: true, get: function () { return number_1.formatNumber; } });
8
8
  var phone_1 = require("./phone");
9
9
  Object.defineProperty(exports, "formatPhone", { enumerable: true, get: function () { return phone_1.formatPhone; } });
10
+ var duration_1 = require("./duration");
11
+ Object.defineProperty(exports, "formatDuration", { enumerable: true, get: function () { return duration_1.formatDuration; } });
12
+ var trim_1 = require("./trim");
13
+ Object.defineProperty(exports, "trim", { enumerable: true, get: function () { return trim_1.trim; } });
14
+ var romanNumerals_1 = require("./romanNumerals");
15
+ Object.defineProperty(exports, "formatRomanNumeral", { enumerable: true, get: function () { return romanNumerals_1.formatRomanNumeral; } });
16
+ var percentage_1 = require("./percentage");
17
+ Object.defineProperty(exports, "formatPercentage", { enumerable: true, get: function () { return percentage_1.formatPercentage; } });
18
+ var fileSize_1 = require("./fileSize");
19
+ Object.defineProperty(exports, "formatFileSize", { enumerable: true, get: function () { return fileSize_1.formatFileSize; } });
20
+ var ordinal_1 = require("./ordinal");
21
+ Object.defineProperty(exports, "formatOrdinal", { enumerable: true, get: function () { return ordinal_1.formatOrdinal; } });
22
+ var listToString_1 = require("./listToString");
23
+ Object.defineProperty(exports, "formatList", { enumerable: true, get: function () { return listToString_1.formatList; } });
24
+ var creditCard_1 = require("./creditCard");
25
+ Object.defineProperty(exports, "formatCreditCard", { enumerable: true, get: function () { return creditCard_1.formatCreditCard; } });
26
+ var octal_1 = require("./octal");
27
+ Object.defineProperty(exports, "formatToOctal", { enumerable: true, get: function () { return octal_1.formatToOctal; } });
28
+ var temperature_1 = require("./temperature");
29
+ Object.defineProperty(exports, "formatTemperature", { enumerable: true, get: function () { return temperature_1.formatTemperature; } });
30
+ var scientific_1 = require("./scientific");
31
+ Object.defineProperty(exports, "formatScientific", { enumerable: true, get: function () { return scientific_1.formatScientific; } });
32
+ var binary_1 = require("./binary");
33
+ Object.defineProperty(exports, "formatToBinary", { enumerable: true, get: function () { return binary_1.formatToBinary; } });
34
+ var hexadecimal_1 = require("./hexadecimal");
35
+ Object.defineProperty(exports, "formatToHexadecimal", { enumerable: true, get: function () { return hexadecimal_1.formatToHexadecimal; } });
36
+ var decimal_1 = require("./decimal");
37
+ Object.defineProperty(exports, "formatToDecimal", { enumerable: true, get: function () { return decimal_1.formatToDecimal; } });
10
38
  const capitalize_2 = require("./capitalize");
11
39
  const number_2 = require("./number");
12
40
  const phone_2 = require("./phone");
41
+ const duration_2 = require("./duration");
42
+ const trim_2 = require("./trim");
43
+ const romanNumerals_2 = require("./romanNumerals");
44
+ const percentage_2 = require("./percentage");
45
+ const fileSize_2 = require("./fileSize");
46
+ const ordinal_2 = require("./ordinal");
47
+ const listToString_2 = require("./listToString");
48
+ const creditCard_2 = require("./creditCard");
49
+ const octal_2 = require("./octal");
50
+ const temperature_2 = require("./temperature");
51
+ const scientific_2 = require("./scientific");
52
+ const binary_2 = require("./binary");
53
+ const hexadecimal_2 = require("./hexadecimal");
54
+ const decimal_2 = require("./decimal");
13
55
  exports.formatting = {
14
56
  capitalize: capitalize_2.capitalize,
15
57
  formatNumber: number_2.formatNumber,
16
58
  formatPhone: phone_2.formatPhone,
59
+ formatDuration: duration_2.formatDuration,
60
+ trim: trim_2.trim,
61
+ formatRomanNumeral: romanNumerals_2.formatRomanNumeral,
62
+ formatPercentage: percentage_2.formatPercentage,
63
+ formatFileSize: fileSize_2.formatFileSize,
64
+ formatOrdinal: ordinal_2.formatOrdinal,
65
+ formatList: listToString_2.formatList,
66
+ formatTemperature: temperature_2.formatTemperature,
67
+ formatScientific: scientific_2.formatScientific,
68
+ formatCreditCard: creditCard_2.formatCreditCard,
69
+ formatToBinary: binary_2.formatToBinary,
70
+ formatToHexadecimal: hexadecimal_2.formatToHexadecimal,
71
+ formatToOctal: octal_2.formatToOctal,
72
+ formatToDecimal: decimal_2.formatToDecimal
17
73
  };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Formats an array of strings into a human-readable list with proper commas and "and".
3
+ *
4
+ * Supports the Oxford comma for lists of three or more items.
5
+ * Returns an empty string for empty arrays.
6
+ *
7
+ * Examples:
8
+ * ["apples", "bananas", "cherries"] → "apples, bananas, and cherries"
9
+ * ["apples", "bananas"] → "apples and bananas"
10
+ * ["apple"] → "apple"
11
+ * [] → ""
12
+ *
13
+ * @param {string[]} arr - The array of strings to format into a readable list.
14
+ * @returns {string} The formatted human-readable list.
15
+ * @throws {TypeError} If the input is not an array of strings.
16
+ */
17
+ export declare function formatList(arr: string[]): string;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatList = formatList;
4
+ /**
5
+ * Formats an array of strings into a human-readable list with proper commas and "and".
6
+ *
7
+ * Supports the Oxford comma for lists of three or more items.
8
+ * Returns an empty string for empty arrays.
9
+ *
10
+ * Examples:
11
+ * ["apples", "bananas", "cherries"] → "apples, bananas, and cherries"
12
+ * ["apples", "bananas"] → "apples and bananas"
13
+ * ["apple"] → "apple"
14
+ * [] → ""
15
+ *
16
+ * @param {string[]} arr - The array of strings to format into a readable list.
17
+ * @returns {string} The formatted human-readable list.
18
+ * @throws {TypeError} If the input is not an array of strings.
19
+ */
20
+ function formatList(arr) {
21
+ if (!Array.isArray(arr)) {
22
+ throw new TypeError('Input must be an array');
23
+ }
24
+ if (!arr.every(item => typeof item === 'string')) {
25
+ throw new TypeError('All elements in the array must be strings');
26
+ }
27
+ const len = arr.length;
28
+ if (len === 0)
29
+ return '';
30
+ if (len === 1)
31
+ return arr[0];
32
+ if (len === 2)
33
+ return `${arr[0]} and ${arr[1]}`;
34
+ return `${arr.slice(0, -1).join(', ')}, and ${arr[len - 1]}`;
35
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Converts a decimal number to its octal (base-8) string representation.
3
+ *
4
+ * Supports negative numbers and an optional "0o" prefix.
5
+ *
6
+ * Examples:
7
+ * 8 → "10"
8
+ * 10 → "12"
9
+ * 255 → "377"
10
+ * 0 → "0"
11
+ *
12
+ * @param {number} num - The decimal number to convert.
13
+ * @param {{ prefix?: boolean }} [options] - Optional formatting options.
14
+ * @returns {string} The octal string representation, optionally prefixed with "0o".
15
+ * @throws {TypeError} If the input is not a number or is NaN.
16
+ */
17
+ export declare function formatToOctal(num: number, options?: {
18
+ prefix?: boolean;
19
+ }): string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatToOctal = formatToOctal;
4
+ /**
5
+ * Converts a decimal number to its octal (base-8) string representation.
6
+ *
7
+ * Supports negative numbers and an optional "0o" prefix.
8
+ *
9
+ * Examples:
10
+ * 8 → "10"
11
+ * 10 → "12"
12
+ * 255 → "377"
13
+ * 0 → "0"
14
+ *
15
+ * @param {number} num - The decimal number to convert.
16
+ * @param {{ prefix?: boolean }} [options] - Optional formatting options.
17
+ * @returns {string} The octal string representation, optionally prefixed with "0o".
18
+ * @throws {TypeError} If the input is not a number or is NaN.
19
+ */
20
+ function formatToOctal(num, options) {
21
+ if (typeof num !== 'number' || Number.isNaN(num)) {
22
+ throw new TypeError('Input must be a number');
23
+ }
24
+ const includePrefix = (options === null || options === void 0 ? void 0 : options.prefix) === true;
25
+ const isNegative = num < 0;
26
+ const absoluteValue = Math.abs(num);
27
+ const octalCore = absoluteValue.toString(8);
28
+ const prefix = includePrefix ? '0o' : '';
29
+ const signedCore = `${prefix}${octalCore}`;
30
+ return isNegative ? `-${signedCore}` : signedCore;
31
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Converts a number into its ordinal string representation (e.g., 1 → "1st", 2 → "2nd").
3
+ *
4
+ * Handles special cases for 11, 12, and 13, which always use "th" regardless of their last digit.
5
+ * Supports both small and large numbers.
6
+ *
7
+ * Examples:
8
+ * 1 → "1st"
9
+ * 2 → "2nd"
10
+ * 3 → "3rd"
11
+ * 4 → "4th"
12
+ * 11 → "11th"
13
+ * 21 → "21st"
14
+ * 113 → "113th"
15
+ *
16
+ * @param {number} num - The number to convert to an ordinal string.
17
+ * @returns {string} The formatted ordinal string (e.g., "21st").
18
+ * @throws {TypeError} If the input is not a number.
19
+ */
20
+ export declare function formatOrdinal(num: number): string;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatOrdinal = formatOrdinal;
4
+ /**
5
+ * Converts a number into its ordinal string representation (e.g., 1 → "1st", 2 → "2nd").
6
+ *
7
+ * Handles special cases for 11, 12, and 13, which always use "th" regardless of their last digit.
8
+ * Supports both small and large numbers.
9
+ *
10
+ * Examples:
11
+ * 1 → "1st"
12
+ * 2 → "2nd"
13
+ * 3 → "3rd"
14
+ * 4 → "4th"
15
+ * 11 → "11th"
16
+ * 21 → "21st"
17
+ * 113 → "113th"
18
+ *
19
+ * @param {number} num - The number to convert to an ordinal string.
20
+ * @returns {string} The formatted ordinal string (e.g., "21st").
21
+ * @throws {TypeError} If the input is not a number.
22
+ */
23
+ function formatOrdinal(num) {
24
+ if (typeof num !== 'number' || Number.isNaN(num)) {
25
+ throw new TypeError('Input must be a number');
26
+ }
27
+ const absNum = Math.abs(num);
28
+ const lastTwoDigits = absNum % 100;
29
+ if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
30
+ return `${num}th`;
31
+ }
32
+ const lastDigit = absNum % 10;
33
+ switch (lastDigit) {
34
+ case 1:
35
+ return `${num}st`;
36
+ case 2:
37
+ return `${num}nd`;
38
+ case 3:
39
+ return `${num}rd`;
40
+ default:
41
+ return `${num}th`;
42
+ }
43
+ }