@scurrlin/stencil 1.34.5 → 1.34.6
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/dist/bin/cli.d.ts +2 -0
- package/dist/bin/cli.js +37 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +36 -0
- package/package.json +33 -6
- package/bin/cli.js +0 -52
- package/src/index.js +0 -60
package/dist/bin/cli.js
ADDED
|
@@ -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.
|
|
3
|
+
"version": "1.34.6",
|
|
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
|
-
};
|