@scurrlin/stencil 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.txt +9 -0
- package/README.md +71 -0
- package/bin/cli.js +52 -0
- package/package.json +24 -0
- package/src/index.js +60 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sean Currlin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
```
|
|
2
|
+
▗▄▄▖▗▄▄▄▖▗▄▄▄▖▗▖ ▗▖ ▗▄▄▖▗▄▄▄▖▗▖
|
|
3
|
+
▐▌ █ ▐▌ ▐▛▚▖▐▌▐▌ █ ▐▌
|
|
4
|
+
▝▀▚▖ █ ▐▛▀▀▘▐▌ ▝▜▌▐▌ █ ▐▌
|
|
5
|
+
▗▄▄▞▘ █ ▐▙▄▄▖▐▌ ▐▌▝▚▄▄▖▗▄█▄▖▐▙▄▄▖
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Whether you are studying for technical interviews, or just starting your coding journey, pattern recognition and memorization are absolutely necessary. It doesn't take a valedictorian to figure that out, but how exactly are you supposed to do that? Between data structures, algorithms, and design patterns, the task of incrementally committing enough of that information to memory can feel impossible. You could spend hours studying fully implemented algorithms only to draw a blank when staring at an empty code editor.
|
|
12
|
+
|
|
13
|
+
Most people when they attempt to memorize something study the full text and then attempt to regurgitate it on a blank page. Shocking, I know... but what if there was a step in between? What if memorization and pattern recognition weren't all or nothing games? This is where Stencil comes in.
|
|
14
|
+
|
|
15
|
+
Stencil is a memorization tool strips code files down to their first letters while preserving spacing, capitalization, and punctuation. The "stencil" of the file is designed to act as a bridge between having something partially memorized to fully memorized. Below is an example of Stencil in action using LeetCode problem 217 "Contains Duplicate":
|
|
16
|
+
|
|
17
|
+
## Example
|
|
18
|
+
|
|
19
|
+
Solution
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
class Solution:
|
|
23
|
+
def containsDuplicate(self, nums: List[int]) -> bool:
|
|
24
|
+
nums.sort()
|
|
25
|
+
n = len(nums)
|
|
26
|
+
for i in range(1, n):
|
|
27
|
+
if nums[i] == nums[i - 1]:
|
|
28
|
+
return True
|
|
29
|
+
return False
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Solution with Stencil
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
c S:
|
|
36
|
+
d c(s, n: L[i]) -> b:
|
|
37
|
+
n.s()
|
|
38
|
+
n = l(n)
|
|
39
|
+
f i i r(1, n):
|
|
40
|
+
i n[i] == n[i - 1]:
|
|
41
|
+
r T
|
|
42
|
+
r F
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Local Installation
|
|
46
|
+
|
|
47
|
+
To install **Stencil** locally, run the following command in the terminal of your directory:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install stencil
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Once installed, you can run it with the following command:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npx stencil path/to/your/file.py --start <start_line> --end <end_line>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Global Installation
|
|
60
|
+
|
|
61
|
+
If you prefer to install **Stencil** globally, run the following command in your terminal:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npm install -g stencil
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Once installed, you can run it with the following command:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
stencil path/to/your/file.py --start <start_line> --end <end_line>
|
|
71
|
+
```
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { transformFile } = require('../src/index');
|
|
4
|
+
const yargs = require('yargs/yargs');
|
|
5
|
+
const { hideBin } = require('yargs/helpers');
|
|
6
|
+
|
|
7
|
+
async function run() {
|
|
8
|
+
const argv = yargs(hideBin(process.argv))
|
|
9
|
+
.usage('Usage: stencil <path> [options]')
|
|
10
|
+
|
|
11
|
+
// Local Installation Example
|
|
12
|
+
.example(
|
|
13
|
+
'npx stencil path/to/file.py --start 2 --end 10',
|
|
14
|
+
'Transform only lines 2-10 (local installation)\n'
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
// Global Installation Example
|
|
18
|
+
.example(
|
|
19
|
+
'stencil path/to/file.py --start 2 --end 10',
|
|
20
|
+
'Transform only lines 2-10 (global installation)'
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
.option('start', {
|
|
24
|
+
alias: 's',
|
|
25
|
+
type: 'number',
|
|
26
|
+
default: null,
|
|
27
|
+
describe: 'Start line number for transformation'
|
|
28
|
+
})
|
|
29
|
+
.option('end', {
|
|
30
|
+
alias: 'e',
|
|
31
|
+
type: 'number',
|
|
32
|
+
default: null,
|
|
33
|
+
describe: 'End line number for transformation'
|
|
34
|
+
})
|
|
35
|
+
.demandCommand(1, 'Please provide the path to the file you wish to transform.')
|
|
36
|
+
.help('h')
|
|
37
|
+
.alias('h', 'help')
|
|
38
|
+
.argv;
|
|
39
|
+
|
|
40
|
+
const filePath = argv._[0];
|
|
41
|
+
const { start, end } = argv;
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const transformedCode = await transformFile(filePath, { startLine: start, endLine: end });
|
|
45
|
+
console.log(transformedCode);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error('Error:', error.message);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
run();
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scurrlin/stencil",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A memorization tool that strips code down to first letters and punctuation only.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"stencil": "./bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node bin/cli.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"yargs": "^17.7.2"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"stencil",
|
|
17
|
+
"memory",
|
|
18
|
+
"study",
|
|
19
|
+
"code",
|
|
20
|
+
"transform"
|
|
21
|
+
],
|
|
22
|
+
"author": "Sean Currlin",
|
|
23
|
+
"license": "MIT"
|
|
24
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const readline = require('readline');
|
|
3
|
+
|
|
4
|
+
async function transformFile(filePath, options = {}) {
|
|
5
|
+
const { startLine = null, endLine = null } = options;
|
|
6
|
+
|
|
7
|
+
// Check if file exists
|
|
8
|
+
if (!fs.existsSync(filePath)) {
|
|
9
|
+
throw new Error(`File not found: ${filePath}`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Create readable stream with UTF-8 encoding
|
|
13
|
+
const fileStream = fs.createReadStream(filePath, { encoding: 'utf-8' });
|
|
14
|
+
|
|
15
|
+
// Handle stream errors
|
|
16
|
+
fileStream.on('error', (err) => {
|
|
17
|
+
throw new Error(`Unable to read file: ${err.message}`);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Create an interface for reading the file line by line
|
|
21
|
+
const rl = readline.createInterface({
|
|
22
|
+
input: fileStream,
|
|
23
|
+
crlfDelay: Infinity
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
let currentLine = 0;
|
|
27
|
+
let transformedLines = [];
|
|
28
|
+
|
|
29
|
+
for await (const line of rl) {
|
|
30
|
+
currentLine++;
|
|
31
|
+
|
|
32
|
+
// Determine if the current line should be transformed
|
|
33
|
+
if (
|
|
34
|
+
(startLine === null || currentLine >= startLine) &&
|
|
35
|
+
(endLine === null || currentLine <= endLine)
|
|
36
|
+
) {
|
|
37
|
+
transformedLines.push(transformLine(line));
|
|
38
|
+
} else {
|
|
39
|
+
transformedLines.push(line);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return transformedLines.join('\n');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function transformLine(line) {
|
|
47
|
+
// Regular expression to match sequences of letters and numbers
|
|
48
|
+
// \p{L} matches any kind of letter from any language
|
|
49
|
+
// \p{N} matches any kind of numeric character
|
|
50
|
+
// The 'u' flag enables Unicode support
|
|
51
|
+
// The 'g' flag enables global matching
|
|
52
|
+
return line.replace(/[\p{L}\p{N}]+/gu, (match) => {
|
|
53
|
+
return match[0]; // Retain only the first character
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
transformFile,
|
|
59
|
+
transformLine
|
|
60
|
+
};
|