maflex-utils 1.0.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/LICENSE +21 -0
- package/README.md +8 -0
- package/index.js +11 -0
- package/package.json +30 -0
- package/src/async.js +21 -0
- package/src/math.js +42 -0
- package/src/string.js +33 -0
- package/src/validation.js +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Maflex
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "maflex-utils",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Lightweight utility helpers for Node.js backend development",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"nodejs",
|
|
8
|
+
"utils",
|
|
9
|
+
"helpers",
|
|
10
|
+
"backend",
|
|
11
|
+
"utility",
|
|
12
|
+
"validation",
|
|
13
|
+
"string",
|
|
14
|
+
"math",
|
|
15
|
+
"async"
|
|
16
|
+
],
|
|
17
|
+
"author": "Maflex",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/USERNAME/maflex-utils.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/USERNAME/maflex-utils/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/USERNAME/maflex-utils#readme",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/async.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Belirtilen milisaniye kadar bekleyen Promise döndürür.
|
|
5
|
+
* @param {number} ms - Bekleme süresi (milisaniye)
|
|
6
|
+
* @returns {Promise<void>}
|
|
7
|
+
*/
|
|
8
|
+
function sleep(ms) {
|
|
9
|
+
if (typeof ms !== 'number' || !Number.isFinite(ms)) {
|
|
10
|
+
throw new TypeError('sleep: "ms" must be a finite number');
|
|
11
|
+
}
|
|
12
|
+
if (ms < 0) {
|
|
13
|
+
throw new RangeError('sleep: "ms" cannot be negative');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
sleep
|
|
21
|
+
};
|
package/src/math.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* İki sayıyı toplar.
|
|
5
|
+
* @param {number} a - İlk sayı
|
|
6
|
+
* @param {number} b - İkinci sayı
|
|
7
|
+
* @returns {number}
|
|
8
|
+
*/
|
|
9
|
+
function sum(a, b) {
|
|
10
|
+
if (typeof a !== 'number' || !Number.isFinite(a)) {
|
|
11
|
+
throw new TypeError('sum: "a" must be a finite number');
|
|
12
|
+
}
|
|
13
|
+
if (typeof b !== 'number' || !Number.isFinite(b)) {
|
|
14
|
+
throw new TypeError('sum: "b" must be a finite number');
|
|
15
|
+
}
|
|
16
|
+
return a + b;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Belirtilen aralıkta rastgele tam sayı üretir (min ve max dahil).
|
|
21
|
+
* @param {number} min - Minimum tam sayı
|
|
22
|
+
* @param {number} max - Maksimum tam sayı
|
|
23
|
+
* @returns {number}
|
|
24
|
+
*/
|
|
25
|
+
function randomInt(min, max) {
|
|
26
|
+
if (!Number.isInteger(min)) {
|
|
27
|
+
throw new TypeError('randomInt: "min" must be an integer');
|
|
28
|
+
}
|
|
29
|
+
if (!Number.isInteger(max)) {
|
|
30
|
+
throw new new TypeError('randomInt: "max" must be an integer');
|
|
31
|
+
}
|
|
32
|
+
if (min > max) {
|
|
33
|
+
throw new RangeError('randomInt: "min" cannot be greater than "max"');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = {
|
|
40
|
+
sum,
|
|
41
|
+
randomInt
|
|
42
|
+
};
|
package/src/string.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Metnin ilk harfini büyütür.
|
|
5
|
+
* @param {string} text - İşlenecek metin
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
function capitalize(text) {
|
|
9
|
+
if (typeof text !== 'string') {
|
|
10
|
+
throw new TypeError('capitalize: "text" must be a string');
|
|
11
|
+
}
|
|
12
|
+
if (text.length === 0) return '';
|
|
13
|
+
|
|
14
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Metni ters çevirir.
|
|
19
|
+
* @param {string} text - İşlenecek metin
|
|
20
|
+
* @returns {string}
|
|
21
|
+
*/
|
|
22
|
+
function reverse(text) {
|
|
23
|
+
if (typeof text !== 'string') {
|
|
24
|
+
throw new TypeError('reverse: "text" must be a string');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return text.split('').reverse().join('');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
capitalize,
|
|
32
|
+
reverse
|
|
33
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Değerin number olup olmadığını kontrol eder.
|
|
5
|
+
* @param {*} value - Kontrol edilecek değer
|
|
6
|
+
* @returns {boolean}
|
|
7
|
+
*/
|
|
8
|
+
function isNumber(value) {
|
|
9
|
+
if (arguments.length !== 1) {
|
|
10
|
+
throw new Error('isNumber: exactly one argument is required');
|
|
11
|
+
}
|
|
12
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Değerin string olup olmadığını kontrol eder.
|
|
17
|
+
* @param {*} value - Kontrol edilecek değer
|
|
18
|
+
* @returns {boolean}
|
|
19
|
+
*/
|
|
20
|
+
function isString(value) {
|
|
21
|
+
if (arguments.length !== 1) {
|
|
22
|
+
throw new Error('isString: exactly one argument is required');
|
|
23
|
+
}
|
|
24
|
+
return typeof value === 'string';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Değerin dizi (array) olup olmadığını kontrol eder.
|
|
29
|
+
* @param {*} value - Kontrol edilecek değer
|
|
30
|
+
* @returns {boolean}
|
|
31
|
+
*/
|
|
32
|
+
function isArray(value) {
|
|
33
|
+
if (arguments.length !== 1) {
|
|
34
|
+
throw new Error('isArray: exactly one argument is required');
|
|
35
|
+
}
|
|
36
|
+
return Array.isArray(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = {
|
|
40
|
+
isNumber,
|
|
41
|
+
isString,
|
|
42
|
+
isArray
|
|
43
|
+
};
|