raid-capacity 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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -0
  3. package/index.js +54 -0
  4. package/package.json +14 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ricco020
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
@@ -0,0 +1,40 @@
1
+ # raid-capacity
2
+
3
+ Compute the **usable capacity**, **fault tolerance** and **efficiency** of a RAID
4
+ array for the common levels (0, 1, 5, 6, 10). Pure arithmetic, zero dependencies.
5
+
6
+ ```js
7
+ const raidCapacity = require('raid-capacity');
8
+
9
+ raidCapacity({ disks: 4, diskSizeGB: 4000, level: 5 });
10
+ // { level:'5', disks:4, diskSizeGB:4000, usableGB:12000, rawGB:16000,
11
+ // faultToleranceDisks:1, efficiencyPercent:75 }
12
+
13
+ raidCapacity({ disks: 4, diskSizeGB: 4000, level: 10 }).usableGB; // 8000
14
+ ```
15
+
16
+ Accepts `level` as a number (`5`) or string (`"raid5"`). Throws on invalid disk
17
+ counts (RAID 5 needs 3+, RAID 6 needs 4+, RAID 10 needs an even count of 4+).
18
+
19
+ ## Levels
20
+
21
+ | Level | Usable | Fault tolerance | Min disks |
22
+ |------|--------|-----------------|-----------|
23
+ | 0 | n x size | 0 disks | 2 |
24
+ | 1 | size (mirror) | n-1 disks | 2 |
25
+ | 5 | (n-1) x size | 1 disk | 3 |
26
+ | 6 | (n-2) x size | 2 disks | 4 |
27
+ | 10 | (n/2) x size | 1 disk (guaranteed) | 4, even |
28
+
29
+ **Note:** capacity assumes identical disks and is a theoretical figure; real
30
+ controllers and filesystems round down a little, and RAID is not a backup.
31
+
32
+ ## Notes
33
+
34
+ Maintained by the team behind [Save My Disk](https://www.save-my-disk.com), a data
35
+ recovery and backup resource. For plain-English guides on RAID, backups and data
36
+ recovery, see [save-my-disk.com](https://www.save-my-disk.com).
37
+
38
+ ## License
39
+
40
+ MIT
package/index.js ADDED
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * raid-capacity
5
+ * Compute the usable capacity, fault tolerance and efficiency of a RAID array
6
+ * for the common levels (0, 1, 5, 6, 10). Pure arithmetic, no dependencies.
7
+ * Capacity assumes identical disks; real controllers round down slightly.
8
+ */
9
+
10
+ var LEVELS = {
11
+ '0': { min: 2, usable: function (n, s) { return n * s; }, tol: function () { return 0; } },
12
+ '1': { min: 2, usable: function (n, s) { return s; }, tol: function (n) { return n - 1; } },
13
+ '5': { min: 3, usable: function (n, s) { return (n - 1) * s; }, tol: function () { return 1; } },
14
+ '6': { min: 4, usable: function (n, s) { return (n - 2) * s; }, tol: function () { return 2; } },
15
+ '10': { min: 4, usable: function (n, s) { return (n / 2) * s; }, tol: function () { return 1; }, evenOnly: true }
16
+ };
17
+
18
+ function normLevel(level) {
19
+ var l = String(level).toLowerCase().replace(/^raid[\s-]?/, '');
20
+ return LEVELS[l] ? l : null;
21
+ }
22
+
23
+ /**
24
+ * @param {object} opts
25
+ * @param {number} opts.disks number of identical disks
26
+ * @param {number} opts.diskSizeGB size of each disk in GB
27
+ * @param {(number|string)} opts.level RAID level: 0,1,5,6,10 (or "raid5")
28
+ * @returns {{level:string, disks:number, diskSizeGB:number, usableGB:number, rawGB:number, faultToleranceDisks:number, efficiencyPercent:number}}
29
+ */
30
+ function raidCapacity(opts) {
31
+ if (!opts || typeof opts !== 'object') { throw new TypeError('expected an options object'); }
32
+ var n = opts.disks, s = opts.diskSizeGB;
33
+ if (!Number.isFinite(n) || n < 1 || n % 1 !== 0) { throw new RangeError('disks must be a positive integer'); }
34
+ if (!Number.isFinite(s) || s <= 0) { throw new RangeError('diskSizeGB must be a positive number'); }
35
+ var key = normLevel(opts.level);
36
+ if (!key) { throw new RangeError('unsupported RAID level (use 0, 1, 5, 6 or 10)'); }
37
+ var spec = LEVELS[key];
38
+ if (n < spec.min) { throw new RangeError('RAID ' + key + ' needs at least ' + spec.min + ' disks'); }
39
+ if (spec.evenOnly && n % 2 !== 0) { throw new RangeError('RAID ' + key + ' needs an even number of disks'); }
40
+ var usable = spec.usable(n, s);
41
+ var raw = n * s;
42
+ return {
43
+ level: key,
44
+ disks: n,
45
+ diskSizeGB: s,
46
+ usableGB: Math.round(usable * 100) / 100,
47
+ rawGB: raw,
48
+ faultToleranceDisks: spec.tol(n),
49
+ efficiencyPercent: Math.round((usable / raw) * 1000) / 10
50
+ };
51
+ }
52
+
53
+ module.exports = raidCapacity;
54
+ module.exports.raidCapacity = raidCapacity;
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "raid-capacity",
3
+ "version": "1.0.0",
4
+ "description": "Compute usable capacity, fault tolerance and efficiency for RAID 0/1/5/6/10 arrays. Pure arithmetic, zero dependencies.",
5
+ "main": "index.js",
6
+ "type": "commonjs",
7
+ "scripts": { "test": "node test.js" },
8
+ "keywords": ["raid", "storage", "capacity", "raid5", "raid6", "raid10", "fault-tolerance", "nas"],
9
+ "homepage": "https://www.save-my-disk.com",
10
+ "author": "ricco020",
11
+ "license": "MIT",
12
+ "engines": { "node": ">=12" },
13
+ "files": ["index.js", "README.md", "LICENSE"]
14
+ }