devkits-chmod 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/README.md +151 -0
  2. package/index.js +180 -0
  3. package/package.json +48 -0
  4. package/test.js +65 -0
package/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # devkits-chmod
2
+
3
+ > Calculate Unix file permissions (chmod) values
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g devkits-chmod
9
+ ```
10
+
11
+ Or use without installation:
12
+
13
+ ```bash
14
+ npx devkits-chmod [args]
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```bash
20
+ # Show what an octal value means
21
+ dk-chmod 755
22
+ dk-chmod 644
23
+ dk-chmod 600
24
+
25
+ # Calculate from symbolic permissions
26
+ dk-chmod --owner rwx --group r-x --other r-x # 755
27
+ dk-chmod --owner rw --group r --other r # 644
28
+
29
+ # Using symbolic notation
30
+ dk-chmod -s u+rwx,g+rx,o+rx # 755
31
+ ```
32
+
33
+ ## Output Example
34
+
35
+ ```
36
+ Chmod Calculator Results
37
+ ========================
38
+
39
+ Octal: 755
40
+
41
+ Permissions:
42
+ Owner: rwx (7)
43
+ Group: r-x (5)
44
+ Other: r-x (5)
45
+
46
+ Binary: 111 101 101
47
+
48
+ Command: chmod 755 <file>
49
+
50
+ Common patterns:
51
+ 777 - rwxrwxrwx (everyone has full access) ⚠️
52
+ 755 - rwxr-xr-x (common for directories)
53
+ 644 - rw-r--r-- (common for files)
54
+ 600 - rw------- (private file)
55
+ 400 - r-------- (read-only, owner only)
56
+ ```
57
+
58
+ ## Permission Values
59
+
60
+ | Value | Binary | Symbolic | Meaning |
61
+ |-------|--------|----------|---------|
62
+ | 7 | 111 | rwx | Read + Write + Execute |
63
+ | 6 | 110 | rw- | Read + Write |
64
+ | 5 | 101 | r-x | Read + Execute |
65
+ | 4 | 100 | r-- | Read only |
66
+ | 3 | 011 | -wx | Write + Execute |
67
+ | 2 | 010 | -w- | Write only |
68
+ | 1 | 001 | --x | Execute only |
69
+ | 0 | 000 | --- | No permissions |
70
+
71
+ ## Why @devkits/chmod?
72
+
73
+ - ✅ Fast - Instant calculation
74
+ - ✅ Zero dependencies - Pure Node.js
75
+ - ✅ Offline - Works without internet
76
+ - ✅ Free - Open source (MIT)
77
+ - ✅ CLI - Use in your terminal
78
+ - ✅ Shows binary and symbolic representations
79
+
80
+ ## Web Version
81
+
82
+ Prefer a GUI? Check out the web version: **https://devkits-tools.surge.sh/tools/chmod-calculator**
83
+
84
+ - 84 developer tools in one PWA
85
+ - Works offline
86
+ - No signup required
87
+
88
+ ## Pro Features
89
+
90
+ Upgrade to Pro for advanced features:
91
+
92
+ - 📦 Batch Processing
93
+ - 🔗 API Access (1000 req/day free)
94
+ - ☁️ Cloud Sync
95
+ - 🎨 Custom Themes
96
+ - 📊 Advanced Analytics
97
+ - 💬 Priority Support
98
+
99
+ **Price:** $9 one-time payment
100
+ **Upgrade:** https://devkits-tools.surge.sh/pro
101
+ **Discount:** Use code `EARLYBIRD-2026` for 20% off
102
+
103
+ ## See Also
104
+
105
+ Part of the **[DevKits Tools](https://devkits-tools.surge.sh)** collection — 80+ free developer tools:
106
+
107
+ ### Popular Tools
108
+
109
+ | Tool | npm Package | Description |
110
+ |------|-------------|-------------|
111
+ | **[Base64](https://devkits-tools.surge.sh/tools/base64)** | `@devkits/base64` | Encode/decode Base64 |
112
+ | **[JSON Formatter](https://devkits-tools.surge.sh/tools/json-formatter)** | `@devkits/json-formatter` | Format and validate JSON |
113
+ | **[Color Converter](https://devkits-tools.surge.sh/tools/color-converter)** | `@devkits/color-converter` | HEX/RGB/HSL conversion |
114
+ | **[UUID Generator](https://devkits-tools.surge.sh/tools/uuid-generator)** | `@devkits/uuid-generator` | Generate unique UUIDs |
115
+ | **[Hash Generator](https://devkits-tools.surge.sh/tools/hash-generator)** | `@devkits/hash-generator` | MD5, SHA1, SHA256, SHA512 |
116
+ | **[Regex Tester](https://devkits-tools.surge.sh/tools/regex-tester)** | `@devkits/regex-tester` | Test regex patterns |
117
+
118
+ ### Other DevKits Tools
119
+
120
+ - **[HTML Tools](https://devkits-tools.surge.sh/tools/html-entities)** — HTML entity encode/decode
121
+ - **[CSS Tools](https://devkits-tools.surge.sh/tools/css-minifier)** — CSS minify/format
122
+ - **[Cron Parser](https://devkits-tools.surge.sh/tools/cron-parser)** — Parse cron expressions
123
+ - **[Case Convert](https://devkits-tools.surge.sh/tools/text-case)** — camelCase, snake_case, etc.
124
+ - **[Slugify](https://devkits-tools.surge.sh/tools/slug-generator)** — Create URL-friendly slugs
125
+ - **[Lorem Ipsum](https://devkits-tools.surge.sh/tools/lorem-ipsum)** — Generate placeholder text
126
+ - **[Password Generator](https://devkits-tools.surge.sh/tools/password-generator)** — Secure passwords
127
+ - **[Text Counter](https://devkits-tools.surge.sh/tools/text-counter)** — Word/char counter
128
+
129
+ ---
130
+
131
+ ### More from DevKits
132
+
133
+ - **[Invoicely](https://invoicely-app.surge.sh)** — Free invoice generator for freelancers
134
+ - **[SnapOG](https://snapog.surge.sh)** — Free OG image generator with 20+ templates
135
+ - **[API Monitor](https://api-monitor-saas.surge.sh)** — Real-time API monitoring
136
+
137
+ ---
138
+
139
+ 👉 **Explore all 80+ developer tools at [DevKits Tools](https://devkits-tools.surge.sh)**
140
+
141
+ ## License
142
+
143
+ MIT © [DevKits Team](https://devkits-tools.surge.sh)
144
+
145
+ ---
146
+
147
+ ## 🚀 API Monitoring for Developers
148
+
149
+ Build better APIs with **API Monitor SaaS** — real-time monitoring, alerting, and analytics.
150
+
151
+ 👉 **Early Access: $1 pre-order (50% off for life)** → https://api-monitor-saas.surge.sh?utm_source=npm&utm_medium=readme&utm_campaign=phase0
package/index.js ADDED
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @devkits/chmod - Calculate Unix file permissions
5
+ *
6
+ * Usage:
7
+ * dk-chmod 755 # Show what 755 means
8
+ * dk-chmod -r wx -w r # Calculate from symbols
9
+ * dk-chmod --symbolic u+rwx,g+rx # Symbolic notation
10
+ *
11
+ * Web version: https://devkits-tools.surge.sh/tools/chmod-calculator
12
+ * Pro features: https://devkits-tools.surge.sh/pro
13
+ */
14
+
15
+ const PERMISSIONS = {
16
+ 7: { binary: '111', symbolic: 'rwx', value: 7 },
17
+ 6: { binary: '110', symbolic: 'rw-', value: 6 },
18
+ 5: { binary: '101', symbolic: 'r-x', value: 5 },
19
+ 4: { binary: '100', symbolic: 'r--', value: 4 },
20
+ 3: { binary: '011', symbolic: '-wx', value: 3 },
21
+ 2: { binary: '010', symbolic: '-w-', value: 2 },
22
+ 1: { binary: '001', symbolic: '--x', value: 1 },
23
+ 0: { binary: '000', symbolic: '---', value: 0 },
24
+ };
25
+
26
+ function parseOctal(octal) {
27
+ const octalStr = octal.toString();
28
+ const digits = octalStr.split('').map(d => parseInt(d, 10));
29
+
30
+ // Pad to 3 or 4 digits
31
+ while (digits.length < 3) {
32
+ digits.unshift(0);
33
+ }
34
+
35
+ const result = {
36
+ octal: digits.join(''),
37
+ owner: PERMISSIONS[digits[digits.length - 3]] || PERMISSIONS[0],
38
+ group: PERMISSIONS[digits[digits.length - 2]] || PERMISSIONS[0],
39
+ other: PERMISSIONS[digits[digits.length - 1]] || PERMISSIONS[0],
40
+ };
41
+
42
+ if (digits.length >= 4) {
43
+ result.special = {
44
+ 4: 'setuid',
45
+ 2: 'setgid',
46
+ 1: 'sticky',
47
+ }[digits[0]] || null;
48
+ }
49
+
50
+ return result;
51
+ }
52
+
53
+ function symbolicToOctal(symbolic) {
54
+ let result = 0;
55
+
56
+ if (symbolic.includes('r')) result += 4;
57
+ if (symbolic.includes('w')) result += 2;
58
+ if (symbolic.includes('x')) result += 1;
59
+
60
+ return result;
61
+ }
62
+
63
+ function showHelp() {
64
+ console.log(`
65
+ @devkits/chmod - Unix file permissions calculator
66
+
67
+ Usage:
68
+ dk-chmod 755 # Show what 755 means
69
+ dk-chmod 644 # Show what 644 means
70
+ dk-chmod -o rwx r-x r-- # Calculate from symbols
71
+ dk-chmod --owner rwx --group r-x # Verbose symbolic
72
+
73
+ Options:
74
+ -o, --octal <n> Show octal permissions
75
+ -s, --symbolic <sym> Symbolic notation (e.g., u+rwx,g+rx)
76
+ --owner <sym> Owner permissions (rwx, rw, etc.)
77
+ --group <sym> Group permissions
78
+ --other <sym> Other permissions
79
+ -h, --help Show this help message
80
+
81
+ Examples:
82
+ dk-chmod 755 # rwxr-xr-x
83
+ dk-chmod 644 # rw-r--r--
84
+ dk-chmod -o rwx r-x r-- # 755
85
+ dk-chmod --owner rw --group r --other r # 644
86
+
87
+ Web version: https://devkits-tools.surge.sh/tools/chmod-calculator
88
+ Pro features: https://devkits-tools.surge.sh/pro
89
+ `);
90
+ }
91
+
92
+ // Main entry point
93
+ const args = process.argv.slice(2);
94
+
95
+ if (!args.length || args.includes('-h') || args.includes('--help')) {
96
+ showHelp();
97
+ process.exit(0);
98
+ }
99
+
100
+ // Parse options
101
+ let ownerSym = null;
102
+ let groupSym = null;
103
+ let otherSym = null;
104
+ let octalValue = null;
105
+
106
+ for (let i = 0; i < args.length; i++) {
107
+ switch (args[i]) {
108
+ case '-o':
109
+ case '--octal':
110
+ octalValue = args[++i];
111
+ break;
112
+ case '--owner':
113
+ ownerSym = args[++i];
114
+ break;
115
+ case '--group':
116
+ groupSym = args[++i];
117
+ break;
118
+ case '--other':
119
+ otherSym = args[++i];
120
+ break;
121
+ case '-s':
122
+ case '--symbolic':
123
+ // Parse symbolic notation like u+rwx,g+rx
124
+ const parts = args[++i].split(',');
125
+ for (const part of parts) {
126
+ const match = part.match(/([ugo])([+\-=])([rwx]+)/);
127
+ if (match) {
128
+ const [, who, op, perms] = match;
129
+ if (who === 'u') ownerSym = perms;
130
+ else if (who === 'g') groupSym = perms;
131
+ else if (who === 'o') otherSym = perms;
132
+ }
133
+ }
134
+ break;
135
+ default:
136
+ // Assume it's an octal value
137
+ if (!octalValue && /^\d+$/.test(args[i])) {
138
+ octalValue = args[i];
139
+ }
140
+ }
141
+ }
142
+
143
+ // Calculate from symbolic
144
+ if (ownerSym || groupSym || otherSym) {
145
+ const owner = ownerSym ? symbolicToOctal(ownerSym) : 0;
146
+ const group = groupSym ? symbolicToOctal(groupSym) : 0;
147
+ const other = otherSym ? symbolicToOctal(otherSym) : 0;
148
+ octalValue = `${owner}${group}${other}`;
149
+ }
150
+
151
+ if (octalValue) {
152
+ const result = parseOctal(octalValue);
153
+
154
+ console.log(`\nChmod Calculator Results`);
155
+ console.log(`========================\n`);
156
+ console.log(`Octal: ${result.octal}`);
157
+ console.log(`\nPermissions:`);
158
+ console.log(` Owner: ${result.owner.symbolic} (${result.owner.value})`);
159
+ console.log(` Group: ${result.group.symbolic} (${result.group.value})`);
160
+ console.log(` Other: ${result.other.symbolic} (${result.other.value})`);
161
+
162
+ if (result.special) {
163
+ console.log(`\nSpecial: ${result.special}`);
164
+ }
165
+
166
+ console.log(`\nBinary: ${result.owner.binary} ${result.group.binary} ${result.other.binary}`);
167
+ console.log(`\nCommand: chmod ${result.octal} <file>`);
168
+
169
+ // Common use cases
170
+ console.log(`\nCommon patterns:`);
171
+ console.log(` 777 - rwxrwxrwx (everyone has full access) ⚠️`);
172
+ console.log(` 755 - rwxr-xr-x (common for directories)`);
173
+ console.log(` 644 - rw-r--r-- (common for files)`);
174
+ console.log(` 600 - rw------- (private file)`);
175
+ console.log(` 400 - r-------- (read-only, owner only)`);
176
+ } else {
177
+ console.error('Error: Please provide an octal value or symbolic permissions');
178
+ showHelp();
179
+ process.exit(1);
180
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "devkits-chmod",
3
+ "version": "1.0.0",
4
+ "description": "Calculate Unix file permissions (chmod) values",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "dk-chmod": "./index.js",
8
+ "chmod-calc": "./index.js"
9
+ },
10
+ "scripts": {
11
+ "test": "node test.js"
12
+ },
13
+ "keywords": [
14
+ "chmod",
15
+ "permissions",
16
+ "unix",
17
+ "linux",
18
+ "file",
19
+ "devkits",
20
+ "developer-tools",
21
+ "cli",
22
+ "command-line",
23
+ "nodejs",
24
+ "utility",
25
+ "productivity",
26
+ "dev-tools",
27
+ "free-tools"
28
+ ],
29
+ "author": "DevKits Team <devkits-auto@protonmail.com>",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/devkits/tools"
34
+ },
35
+ "homepage": "https://devkits-tools.surge.sh/tools/chmod-calculator",
36
+ "bugs": {
37
+ "url": "https://github.com/devkits/tools/issues"
38
+ },
39
+ "engines": {
40
+ "node": ">=14.0.0"
41
+ },
42
+ "files": [
43
+ "index.js",
44
+ "README.md",
45
+ "test.js"
46
+ ],
47
+ "dependencies": {}
48
+ }
package/test.js ADDED
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Tests for @devkits/chmod
5
+ */
6
+
7
+ const { execSync } = require('child_process');
8
+
9
+ const tests = [
10
+ {
11
+ name: '755 shows rwxr-xr-x',
12
+ cmd: 'node index.js 755',
13
+ check: (result) => result.includes('rwx') && result.includes('r-x') && result.includes('755')
14
+ },
15
+ {
16
+ name: '644 shows rw-r--r--',
17
+ cmd: 'node index.js 644',
18
+ check: (result) => result.includes('rw-') && result.includes('r--') && result.includes('644')
19
+ },
20
+ {
21
+ name: '600 shows rw-------',
22
+ cmd: 'node index.js 600',
23
+ check: (result) => result.includes('rw-') && result.includes('---')
24
+ },
25
+ {
26
+ name: 'Symbolic to octal (rwx r-x r-x)',
27
+ cmd: 'node index.js --owner rwx --group r-x --other r-x',
28
+ check: (result) => result.includes('755')
29
+ },
30
+ {
31
+ name: 'Symbolic to octal (rw r r)',
32
+ cmd: 'node index.js --owner rw --group r --other r',
33
+ check: (result) => result.includes('644')
34
+ },
35
+ {
36
+ name: 'Output includes binary representation',
37
+ cmd: 'node index.js 755',
38
+ check: (result) => result.includes('Binary:') && result.includes('111')
39
+ },
40
+ ];
41
+
42
+ let passed = 0;
43
+ let failed = 0;
44
+
45
+ console.log('Running @devkits/chmod tests...\n');
46
+
47
+ for (const test of tests) {
48
+ try {
49
+ const result = execSync(test.cmd, { encoding: 'utf8' }).trim();
50
+ if (test.check(result)) {
51
+ console.log(`✅ ${test.name}`);
52
+ passed++;
53
+ } else {
54
+ console.log(`❌ ${test.name}`);
55
+ console.log(` Got: ${result.substring(0, 100)}...`);
56
+ failed++;
57
+ }
58
+ } catch (err) {
59
+ console.log(`❌ ${test.name} - Error: ${err.message}`);
60
+ failed++;
61
+ }
62
+ }
63
+
64
+ console.log(`\n${passed}/${tests.length} tests passed`);
65
+ process.exit(failed > 0 ? 1 : 0);