stringzy 4.1.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.
- package/.github/workflows/auto-assign.yml +26 -0
- package/CODE_OF_CONDUCT.MD +115 -0
- package/README.md +591 -79
- package/dist/analyzing/checkMultiplePatterns.d.ts +2 -2
- package/dist/analyzing/checkMultiplePatterns.js +43 -31
- package/dist/analyzing/index.d.ts +3 -0
- package/dist/analyzing/index.js +6 -2
- package/dist/analyzing/lexicographicalRank.d.ts +26 -0
- package/dist/analyzing/lexicographicalRank.js +66 -0
- package/dist/formatting/binary.d.ts +24 -0
- package/dist/formatting/binary.js +49 -0
- package/dist/formatting/creditCard.d.ts +8 -0
- package/dist/formatting/creditCard.js +28 -0
- package/dist/formatting/decimal.d.ts +21 -0
- package/dist/formatting/decimal.js +73 -0
- package/dist/formatting/duration.d.ts +27 -0
- package/dist/formatting/duration.js +92 -0
- package/dist/formatting/fileSize.d.ts +18 -0
- package/dist/formatting/fileSize.js +39 -0
- package/dist/formatting/hexadecimal.d.ts +14 -0
- package/dist/formatting/hexadecimal.js +38 -0
- package/dist/formatting/index.d.ts +42 -0
- package/dist/formatting/index.js +57 -1
- package/dist/formatting/listToString.d.ts +17 -0
- package/dist/formatting/listToString.js +35 -0
- package/dist/formatting/octal.d.ts +19 -0
- package/dist/formatting/octal.js +31 -0
- package/dist/formatting/ordinal.d.ts +20 -0
- package/dist/formatting/ordinal.js +43 -0
- package/dist/formatting/percentage.d.ts +19 -0
- package/dist/formatting/percentage.js +31 -0
- package/dist/formatting/romanNumerals.d.ts +20 -0
- package/dist/formatting/romanNumerals.js +53 -0
- package/dist/formatting/scientific.d.ts +14 -0
- package/dist/formatting/scientific.js +24 -0
- package/dist/formatting/temperature.d.ts +6 -0
- package/dist/formatting/temperature.js +27 -0
- package/dist/formatting/trim.d.ts +10 -0
- package/dist/formatting/trim.js +20 -0
- package/dist/index.d.ts +17 -0
- package/dist/tests/analyzing/lexicographicalRank.test.d.ts +1 -0
- package/dist/tests/analyzing/lexicographicalRank.test.js +43 -0
- package/dist/tests/formatting/binary.test.d.ts +1 -0
- package/dist/tests/formatting/binary.test.js +53 -0
- package/dist/tests/formatting/creditCard.test.d.ts +1 -0
- package/dist/tests/formatting/creditCard.test.js +31 -0
- package/dist/tests/formatting/decimal.test.d.ts +1 -0
- package/dist/tests/formatting/decimal.test.js +62 -0
- package/dist/tests/formatting/duration.test.d.ts +1 -0
- package/dist/tests/formatting/duration.test.js +61 -0
- package/dist/tests/formatting/fileSize.test.d.ts +1 -0
- package/dist/tests/formatting/fileSize.test.js +39 -0
- package/dist/tests/formatting/hexadecimal.test.d.ts +1 -0
- package/dist/tests/formatting/hexadecimal.test.js +38 -0
- package/dist/tests/formatting/listToString.test.d.ts +1 -0
- package/dist/tests/formatting/listToString.test.js +37 -0
- package/dist/tests/formatting/octal.test.d.ts +1 -0
- package/dist/tests/formatting/octal.test.js +36 -0
- package/dist/tests/formatting/ordinal.test.d.ts +1 -0
- package/dist/tests/formatting/ordinal.test.js +37 -0
- package/dist/tests/formatting/percentage.test.d.ts +1 -0
- package/dist/tests/formatting/percentage.test.js +38 -0
- package/dist/tests/formatting/romanNumerals.test.d.ts +1 -0
- package/dist/tests/formatting/romanNumerals.test.js +35 -0
- package/dist/tests/formatting/scientific.test.d.ts +1 -0
- package/dist/tests/formatting/scientific.test.js +35 -0
- package/dist/tests/formatting/temperature.test.d.ts +1 -0
- package/dist/tests/formatting/temperature.test.js +34 -0
- package/dist/tests/formatting/trim.test.d.ts +1 -0
- package/dist/tests/formatting/trim.test.js +42 -0
- package/dist/tests/transformations/stringPermutations.test.js +70 -0
- package/dist/tests/validations/isIPv6.test.d.ts +1 -0
- package/dist/tests/validations/isIPv6.test.js +65 -0
- package/dist/transformations/index.d.ts +3 -2
- package/dist/transformations/index.js +3 -1
- package/dist/transformations/stringPermutations.d.ts +23 -1
- package/dist/transformations/stringPermutations.js +127 -1
- package/dist/validations/index.d.ts +3 -0
- package/dist/validations/index.js +5 -1
- package/dist/validations/isIPv6.d.ts +24 -0
- package/dist/validations/isIPv6.js +45 -0
- package/package.json +1 -1
|
@@ -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
|
};
|
package/dist/formatting/index.js
CHANGED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a number into a percentage string with configurable decimal precision.
|
|
3
|
+
*
|
|
4
|
+
* Supports positive, negative, and whole numbers.
|
|
5
|
+
*
|
|
6
|
+
* Examples:
|
|
7
|
+
* 0.567 → "56.70%"
|
|
8
|
+
* 0.567 → "56.7%" (precision = 1)
|
|
9
|
+
* 0.5 → "50%"
|
|
10
|
+
* 1 → "100%"
|
|
11
|
+
* -0.25 → "-25%"
|
|
12
|
+
* 50 → "5000%"
|
|
13
|
+
*
|
|
14
|
+
* @param {number} num - The number to convert into a percentage.
|
|
15
|
+
* @param {number} [precision=2] - The number of decimal places to include.
|
|
16
|
+
* @returns {string} The formatted percentage string.
|
|
17
|
+
* @throws {TypeError} If the input is not a number or precision is not a number.
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatPercentage(num: number, precision?: number): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatPercentage = formatPercentage;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a number into a percentage string with configurable decimal precision.
|
|
6
|
+
*
|
|
7
|
+
* Supports positive, negative, and whole numbers.
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
* 0.567 → "56.70%"
|
|
11
|
+
* 0.567 → "56.7%" (precision = 1)
|
|
12
|
+
* 0.5 → "50%"
|
|
13
|
+
* 1 → "100%"
|
|
14
|
+
* -0.25 → "-25%"
|
|
15
|
+
* 50 → "5000%"
|
|
16
|
+
*
|
|
17
|
+
* @param {number} num - The number to convert into a percentage.
|
|
18
|
+
* @param {number} [precision=2] - The number of decimal places to include.
|
|
19
|
+
* @returns {string} The formatted percentage string.
|
|
20
|
+
* @throws {TypeError} If the input is not a number or precision is not a number.
|
|
21
|
+
*/
|
|
22
|
+
function formatPercentage(num, precision = 2) {
|
|
23
|
+
if (typeof num !== 'number' || Number.isNaN(num)) {
|
|
24
|
+
throw new TypeError('Input must be a number');
|
|
25
|
+
}
|
|
26
|
+
if (typeof precision !== 'number' || Number.isNaN(precision) || precision < 0) {
|
|
27
|
+
throw new TypeError('Precision must be a non-negative number');
|
|
28
|
+
}
|
|
29
|
+
const percentage = num * 100;
|
|
30
|
+
return `${percentage.toFixed(precision)}%`;
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a positive integer into its Roman numeral representation.
|
|
3
|
+
*
|
|
4
|
+
* Supports numbers from 1 to 3999 using standard Roman numeral notation.
|
|
5
|
+
*
|
|
6
|
+
* Examples:
|
|
7
|
+
* 1 → "I"
|
|
8
|
+
* 4 → "IV"
|
|
9
|
+
* 9 → "IX"
|
|
10
|
+
* 58 → "LVIII"
|
|
11
|
+
* 1994 → "MCMXCIV"
|
|
12
|
+
* 2025 → "MMXXV"
|
|
13
|
+
* 3999 → "MMMCMXCIX"
|
|
14
|
+
*
|
|
15
|
+
* @param {number} num - The positive integer to convert (1–3999).
|
|
16
|
+
* @returns {string} The Roman numeral representation of the given number.
|
|
17
|
+
* @throws {RangeError} If the number is less than or equal to 0, or greater than 3999.
|
|
18
|
+
* @throws {TypeError} If the input is not a number.
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatRomanNumeral(num: number): string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatRomanNumeral = formatRomanNumeral;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a positive integer into its Roman numeral representation.
|
|
6
|
+
*
|
|
7
|
+
* Supports numbers from 1 to 3999 using standard Roman numeral notation.
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
* 1 → "I"
|
|
11
|
+
* 4 → "IV"
|
|
12
|
+
* 9 → "IX"
|
|
13
|
+
* 58 → "LVIII"
|
|
14
|
+
* 1994 → "MCMXCIV"
|
|
15
|
+
* 2025 → "MMXXV"
|
|
16
|
+
* 3999 → "MMMCMXCIX"
|
|
17
|
+
*
|
|
18
|
+
* @param {number} num - The positive integer to convert (1–3999).
|
|
19
|
+
* @returns {string} The Roman numeral representation of the given number.
|
|
20
|
+
* @throws {RangeError} If the number is less than or equal to 0, or greater than 3999.
|
|
21
|
+
* @throws {TypeError} If the input is not a number.
|
|
22
|
+
*/
|
|
23
|
+
function formatRomanNumeral(num) {
|
|
24
|
+
if (typeof num !== 'number' || Number.isNaN(num)) {
|
|
25
|
+
throw new TypeError('Input must be a number');
|
|
26
|
+
}
|
|
27
|
+
if (num <= 0) {
|
|
28
|
+
throw new RangeError('Roman numerals are only defined for positive integers');
|
|
29
|
+
}
|
|
30
|
+
if (num > 3999) {
|
|
31
|
+
throw new RangeError('Roman numerals are supported only up to 3999');
|
|
32
|
+
}
|
|
33
|
+
const values = [
|
|
34
|
+
1000, 900, 500, 400,
|
|
35
|
+
100, 90, 50, 40,
|
|
36
|
+
10, 9, 5, 4, 1
|
|
37
|
+
];
|
|
38
|
+
const symbols = [
|
|
39
|
+
'M', 'CM', 'D', 'CD',
|
|
40
|
+
'C', 'XC', 'L', 'XL',
|
|
41
|
+
'X', 'IX', 'V', 'IV', 'I'
|
|
42
|
+
];
|
|
43
|
+
let result = '';
|
|
44
|
+
let i = 0;
|
|
45
|
+
while (num > 0) {
|
|
46
|
+
while (num >= values[i]) {
|
|
47
|
+
result += symbols[i];
|
|
48
|
+
num -= values[i];
|
|
49
|
+
}
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a number to scientific (exponential) notation.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} num - The number to convert.
|
|
5
|
+
* @param {object} [options] - Optional formatting settings.
|
|
6
|
+
* @param {number} [options.precision=2] - Number of digits after the decimal point.
|
|
7
|
+
* @param {boolean} [options.uppercase=false] - Whether to use uppercase "E" in the notation.
|
|
8
|
+
* @returns {string} Scientific notation of the number.
|
|
9
|
+
* @throws {TypeError} If input is not a valid number.
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatScientific(num: number, options?: {
|
|
12
|
+
precision?: number;
|
|
13
|
+
uppercase?: boolean;
|
|
14
|
+
}): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatScientific = formatScientific;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a number to scientific (exponential) notation.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} num - The number to convert.
|
|
8
|
+
* @param {object} [options] - Optional formatting settings.
|
|
9
|
+
* @param {number} [options.precision=2] - Number of digits after the decimal point.
|
|
10
|
+
* @param {boolean} [options.uppercase=false] - Whether to use uppercase "E" in the notation.
|
|
11
|
+
* @returns {string} Scientific notation of the number.
|
|
12
|
+
* @throws {TypeError} If input is not a valid number.
|
|
13
|
+
*/
|
|
14
|
+
function formatScientific(num, options) {
|
|
15
|
+
if (typeof num !== 'number' || isNaN(num)) {
|
|
16
|
+
throw new TypeError('Input must be a valid number');
|
|
17
|
+
}
|
|
18
|
+
const { precision = 2, uppercase = false } = options || {};
|
|
19
|
+
let scientific = num.toExponential(precision);
|
|
20
|
+
if (uppercase) {
|
|
21
|
+
scientific = scientific.replace('e', 'E');
|
|
22
|
+
}
|
|
23
|
+
return scientific;
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatTemperature = formatTemperature;
|
|
4
|
+
function formatTemperature(value, options) {
|
|
5
|
+
const { from, to, precision = 2 } = options;
|
|
6
|
+
const conversions = {
|
|
7
|
+
'C_F': (v) => (v * 9) / 5 + 32,
|
|
8
|
+
'C_K': (v) => v + 273.15,
|
|
9
|
+
'F_C': (v) => ((v - 32) * 5) / 9,
|
|
10
|
+
'F_K': (v) => ((v - 32) * 5) / 9 + 273.15,
|
|
11
|
+
'K_C': (v) => v - 273.15,
|
|
12
|
+
'K_F': (v) => ((v - 273.15) * 9) / 5 + 32
|
|
13
|
+
};
|
|
14
|
+
const conversionKey = `${from}_${to}`;
|
|
15
|
+
const convert = conversions[conversionKey];
|
|
16
|
+
if (!convert) {
|
|
17
|
+
throw new Error(`Invalid conversion from ${from} to ${to}.`);
|
|
18
|
+
}
|
|
19
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
20
|
+
throw new Error('Invalid temperature value.');
|
|
21
|
+
}
|
|
22
|
+
const convertedValue = convert(value);
|
|
23
|
+
if (to === 'K') {
|
|
24
|
+
return `${convertedValue.toFixed(precision)}K`;
|
|
25
|
+
}
|
|
26
|
+
return `${convertedValue.toFixed(precision)}°${to}`;
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes unnecessary whitespace from a string.
|
|
3
|
+
* This includes leading/trailing spaces, multiple consecutive spaces, tabs, and line breaks.
|
|
4
|
+
* The result is a clean, single-spaced string.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} str - The input string to format.
|
|
7
|
+
* @returns {string} The trimmed and normalized string.
|
|
8
|
+
* @throws {TypeError} If the input is not a string.
|
|
9
|
+
*/
|
|
10
|
+
export declare function trim(str: string): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trim = trim;
|
|
4
|
+
/**
|
|
5
|
+
* Removes unnecessary whitespace from a string.
|
|
6
|
+
* This includes leading/trailing spaces, multiple consecutive spaces, tabs, and line breaks.
|
|
7
|
+
* The result is a clean, single-spaced string.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} str - The input string to format.
|
|
10
|
+
* @returns {string} The trimmed and normalized string.
|
|
11
|
+
* @throws {TypeError} If the input is not a string.
|
|
12
|
+
*/
|
|
13
|
+
function trim(str) {
|
|
14
|
+
if (typeof str !== 'string') {
|
|
15
|
+
throw new TypeError('Input must be a string');
|
|
16
|
+
}
|
|
17
|
+
// 1. Trim leading/trailing whitespace (including newlines/tabs)
|
|
18
|
+
// 2. Replace multiple internal whitespace chars (including \n, \t) with a single space
|
|
19
|
+
return str.trim().replace(/\s+/g, ' ');
|
|
20
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -15,11 +15,26 @@ declare const _default: {
|
|
|
15
15
|
checkMultiplePatterns: typeof import("./analyzing").checkMultiplePatterns;
|
|
16
16
|
checkSubsequence: typeof import("./analyzing").checkSubsequence;
|
|
17
17
|
checkStringRotations: typeof import("./analyzing").checkStringRotations;
|
|
18
|
+
lexicographicalRank: typeof import("./analyzing").lexicographicalRank;
|
|
18
19
|
};
|
|
19
20
|
formatting: {
|
|
20
21
|
capitalize: typeof import("./formatting").capitalize;
|
|
21
22
|
formatNumber: typeof import("./formatting").formatNumber;
|
|
22
23
|
formatPhone: typeof import("./formatting").formatPhone;
|
|
24
|
+
formatDuration: typeof import("./formatting").formatDuration;
|
|
25
|
+
trim: typeof import("./formatting").trim;
|
|
26
|
+
formatRomanNumeral: typeof import("./formatting").formatRomanNumeral;
|
|
27
|
+
formatPercentage: typeof import("./formatting").formatPercentage;
|
|
28
|
+
formatFileSize: typeof import("./formatting").formatFileSize;
|
|
29
|
+
formatOrdinal: typeof import("./formatting").formatOrdinal;
|
|
30
|
+
formatList: typeof import("./formatting").formatList;
|
|
31
|
+
formatTemperature: typeof import("./formatting").formatTemperature;
|
|
32
|
+
formatScientific: typeof import("./formatting").formatScientific;
|
|
33
|
+
formatCreditCard: typeof import("./formatting").formatCreditCard;
|
|
34
|
+
formatToBinary: typeof import("./formatting").formatToBinary;
|
|
35
|
+
formatToHexadecimal: typeof import("./formatting").formatToHexadecimal;
|
|
36
|
+
formatToOctal: typeof import("./formatting").formatToOctal;
|
|
37
|
+
formatToDecimal: typeof import("./formatting").formatToDecimal;
|
|
23
38
|
};
|
|
24
39
|
transformations: {
|
|
25
40
|
camelCase: typeof import("./transformations").camelCase;
|
|
@@ -41,6 +56,7 @@ declare const _default: {
|
|
|
41
56
|
numberToText: typeof import("./transformations").numberToText;
|
|
42
57
|
reverseWordsInString: typeof import("./transformations").reverseWordsInString;
|
|
43
58
|
stringPermutations: typeof import("./transformations").stringPermutations;
|
|
59
|
+
stringPermutationsGenerator: typeof import("./transformations").stringPermutationsGenerator;
|
|
44
60
|
stringCombinations: typeof import("./transformations").stringCombinations;
|
|
45
61
|
};
|
|
46
62
|
validations: {
|
|
@@ -51,6 +67,7 @@ declare const _default: {
|
|
|
51
67
|
isSlug: typeof import("./validations").isSlug;
|
|
52
68
|
isURL: typeof import("./validations").isURL;
|
|
53
69
|
isIPv4: typeof import("./validations").isIPv4;
|
|
70
|
+
isIPv6: typeof import("./validations").isIPv6;
|
|
54
71
|
isHexColor: typeof import("./validations").isHexColor;
|
|
55
72
|
isPalindrome: typeof import("./validations").isPalindrome;
|
|
56
73
|
isLowerCase: typeof import("./validations").isLowerCase;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|