@scurrlin/stencil 1.34.5 → 1.34.7

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/README.md CHANGED
@@ -16,7 +16,7 @@ Whether you are studying for technical interviews, or just starting your coding
16
16
 
17
17
  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.
18
18
 
19
- Stencil is a language-agnostic memorization tool that 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 and fully memorized. Below is an example of Stencil in action using LeetCode problem 371 "Sum of Two Integers":
19
+ Stencil is a language-agnostic memorization tool that 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 and fully memorized. Below is an example of Stencil in action using LeetCode problem 372 "Super Pow":
20
20
 
21
21
  ## Example
22
22
 
@@ -24,28 +24,28 @@ Solution
24
24
 
25
25
  ```python
26
26
  class Solution:
27
- def getSum(self, a: int, b: int) -> int:
28
- mask = 0xffffffff
29
- while (b & mask) > 0:
30
- carry = ( a & b ) << 1
31
- a = (a ^ b)
32
- b = carry
33
-
34
- return (a & mask) if b > 0 else a
27
+ def superPow(self, a: int, b: List[int]) -> int:
28
+ exp = 0
29
+ for e in b:
30
+ exp = e + 10 * exp
31
+ exp %= 1140
32
+ if exp == 0:
33
+ exp = 1140
34
+ return pow(a, exp, 1337)
35
35
  ```
36
36
 
37
37
  Solution with Stencil
38
38
 
39
39
  ```python
40
40
  c S:
41
- d g(s, a: i, b: i) -> i:
42
- m = 0
43
- w (b & m) > 0:
44
- c = ( a & b ) << 1
45
- a = (a ^ b)
46
- b = c
47
-
48
- r (a & m) i b > 0 e a
41
+ d s(s, a: i, b: L[i]) -> i:
42
+ e = 0
43
+ f e i b:
44
+ e = e + 1 * e
45
+ e %= 1
46
+ i e == 0:
47
+ e = 1
48
+ r p(a, e, 1)
49
49
  ```
50
50
 
51
51
  ## Local Installation
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ import { transformFile } from '../src/index.js';
3
+ import yargs from 'yargs';
4
+ import { hideBin } from 'yargs/helpers';
5
+ async function run() {
6
+ const argv = await yargs(hideBin(process.argv))
7
+ .usage('Usage: stencil <path> [options]')
8
+ .example('npx stencil path/to/file.py --start 2 --end 10', 'Transform only lines 2-10 (local installation)\n')
9
+ .example('stencil path/to/file.py --start 2 --end 10', 'Transform only lines 2-10 (global installation)')
10
+ .option('start', {
11
+ alias: 's',
12
+ type: 'number',
13
+ default: undefined,
14
+ describe: 'Start line number for transformation'
15
+ })
16
+ .option('end', {
17
+ alias: 'e',
18
+ type: 'number',
19
+ default: undefined,
20
+ describe: 'End line number for transformation'
21
+ })
22
+ .demandCommand(1, 'Please provide the path to the file you wish to transform.')
23
+ .help('h')
24
+ .alias('h', 'help')
25
+ .argv;
26
+ const filePath = argv._[0];
27
+ const { start, end } = argv;
28
+ try {
29
+ const transformedCode = await transformFile(filePath, { startLine: start, endLine: end });
30
+ console.log(transformedCode);
31
+ }
32
+ catch (error) {
33
+ console.error('Error:', error.message);
34
+ process.exit(1);
35
+ }
36
+ }
37
+ run();
@@ -0,0 +1,7 @@
1
+ interface TransformOptions {
2
+ startLine?: number | null;
3
+ endLine?: number | null;
4
+ }
5
+ export declare function transformFile(filePath: string, options?: TransformOptions): Promise<string>;
6
+ export declare function transformLine(line: string): string;
7
+ export {};
@@ -0,0 +1,36 @@
1
+ import fs from 'node:fs';
2
+ import readline from 'node:readline';
3
+ export async function transformFile(filePath, options = {}) {
4
+ const { startLine = null, endLine = null } = options;
5
+ if (!fs.existsSync(filePath)) {
6
+ throw new Error(`File not found: ${filePath}`);
7
+ }
8
+ const fileStream = fs.createReadStream(filePath, { encoding: 'utf-8' });
9
+ fileStream.on('error', (err) => {
10
+ throw new Error(`Unable to read file: ${err.message}`);
11
+ });
12
+ const rl = readline.createInterface({
13
+ input: fileStream,
14
+ crlfDelay: Infinity
15
+ });
16
+ let currentLine = 0;
17
+ const transformedLines = [];
18
+ for await (const line of rl) {
19
+ currentLine++;
20
+ if ((startLine === null || currentLine >= startLine) &&
21
+ (endLine === null || currentLine <= endLine)) {
22
+ transformedLines.push(transformLine(line));
23
+ }
24
+ else {
25
+ transformedLines.push(line);
26
+ }
27
+ }
28
+ return transformedLines.join('\n');
29
+ }
30
+ export function transformLine(line) {
31
+ // \p{L} matches any kind of letter from any language
32
+ // \p{N} matches any kind of numeric character
33
+ return line.replace(/[\p{L}\p{N}]+/gu, (match) => {
34
+ return match[0];
35
+ });
36
+ }
package/package.json CHANGED
@@ -1,13 +1,33 @@
1
1
  {
2
2
  "name": "@scurrlin/stencil",
3
- "version": "1.34.5",
3
+ "version": "1.34.7",
4
+ "type": "module",
4
5
  "description": "A memorization tool that strips code down to first letters and punctuation only.",
5
- "main": "src/index.js",
6
+ "main": "dist/src/index.js",
7
+ "types": "dist/src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/src/index.d.ts",
11
+ "import": "./dist/src/index.js"
12
+ }
13
+ },
6
14
  "bin": {
7
- "stencil": "./bin/cli.js"
15
+ "stencil": "./dist/bin/cli.js"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE.txt"
21
+ ],
22
+ "engines": {
23
+ "node": ">=22"
8
24
  },
9
25
  "scripts": {
10
- "start": "node bin/cli.js"
26
+ "start": "node dist/bin/cli.js",
27
+ "build": "tsc",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest",
30
+ "prepublishOnly": "npm run build && npm test"
11
31
  },
12
32
  "dependencies": {
13
33
  "yargs": "^17.7.2"
@@ -20,5 +40,12 @@
20
40
  "leetcode"
21
41
  ],
22
42
  "author": "Sean Currlin",
23
- "license": "MIT"
24
- }
43
+ "license": "MIT",
44
+ "devDependencies": {
45
+ "@types/node": "^25.5.0",
46
+ "@types/yargs": "^17.0.35",
47
+ "typescript": "^6.0.2",
48
+ "vite": "^8.0.2",
49
+ "vitest": "^4.1.1"
50
+ }
51
+ }
package/bin/cli.js DELETED
@@ -1,52 +0,0 @@
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/src/index.js DELETED
@@ -1,60 +0,0 @@
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 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
- // Regex 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
- // 'u' flag enables Unicode support
51
- // '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
- };