@dangayle/rustlike 0.1.0 → 0.1.1
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 +33 -0
- package/dist/async-iter-BY_bNd1c.cjs +2 -0
- package/dist/{async-iter-3iu4aRtf.cjs.map → async-iter-BY_bNd1c.cjs.map} +1 -1
- package/dist/async-iter-D51Pm8tA.mjs +2 -0
- package/dist/{async-iter-aLdg-qp2.mjs.map → async-iter-D51Pm8tA.mjs.map} +1 -1
- package/dist/index.cjs +1 -476
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -442
- package/dist/index.mjs.map +1 -1
- package/dist/node.cjs +2 -117
- package/dist/node.cjs.map +1 -1
- package/dist/node.mjs +2 -86
- package/dist/node.mjs.map +1 -1
- package/package.json +33 -23
- package/dist/async-iter-3iu4aRtf.cjs +0 -1129
- package/dist/async-iter-aLdg-qp2.mjs +0 -1009
package/dist/node.cjs
CHANGED
|
@@ -1,118 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
-
key = keys[i];
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: ((k) => from[k]).bind(null, key),
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
-
value: mod,
|
|
25
|
-
enumerable: true
|
|
26
|
-
}) : target, mod));
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
const require_async_iter = require('./async-iter-3iu4aRtf.cjs');
|
|
30
|
-
let fs = require("fs");
|
|
31
|
-
fs = __toESM(fs);
|
|
32
|
-
let readline = require("readline");
|
|
33
|
-
readline = __toESM(readline);
|
|
34
|
-
|
|
35
|
-
//#region src/node.ts
|
|
36
|
-
/**
|
|
37
|
-
* Node.js-specific utilities for rustlike.
|
|
38
|
-
*
|
|
39
|
-
* This module contains functions that depend on Node.js built-in modules
|
|
40
|
-
* (fs, readline) and should only be imported in Node.js environments.
|
|
41
|
-
* Browser and edge runtime consumers should use the main 'rustlike' entry point.
|
|
42
|
-
*
|
|
43
|
-
* Import from 'rustlike/node' to access these functions.
|
|
44
|
-
*/
|
|
45
|
-
/**
|
|
46
|
-
* Create an Iter that lazily reads lines from a file.
|
|
47
|
-
* Uses Node.js fs.readFileSync but yields lines lazily via generator.
|
|
48
|
-
*
|
|
49
|
-
* Note: This reads the entire file into memory but yields lines lazily.
|
|
50
|
-
* For truly streaming line-by-line reading, use asyncIterLines.
|
|
51
|
-
*
|
|
52
|
-
* @param filepath - Path to the file to read
|
|
53
|
-
* @returns Result with Iter<string> on success, error message on failure
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* const lines = iterLinesSync('data.txt');
|
|
57
|
-
* lines.match({
|
|
58
|
-
* ok: (iter) => iter.skip(1).map(parseLine).collect(),
|
|
59
|
-
* err: (e) => console.error(e)
|
|
60
|
-
* });
|
|
61
|
-
*/
|
|
62
|
-
function iterLinesSync(filepath) {
|
|
63
|
-
try {
|
|
64
|
-
const lines = fs.readFileSync(filepath, "utf-8").split("\n");
|
|
65
|
-
if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
|
|
66
|
-
return require_async_iter.Ok(require_async_iter.iter(lines));
|
|
67
|
-
} catch (error) {
|
|
68
|
-
if (error instanceof Error) return require_async_iter.Err(`Failed to read file '${filepath}': ${error.message}`);
|
|
69
|
-
return require_async_iter.Err(`Failed to read file '${filepath}': ${String(error)}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Create an AsyncIter that reads lines from a file using streaming.
|
|
74
|
-
* Truly memory-efficient - reads lines on-demand without loading entire file.
|
|
75
|
-
*
|
|
76
|
-
* Uses Node.js readline with createReadStream for efficient streaming.
|
|
77
|
-
*
|
|
78
|
-
* @param filepath - Path to the file to read
|
|
79
|
-
* @returns Promise of Result with AsyncIter<string> on success, error message on failure
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* const result = await asyncIterLines('large-log.txt');
|
|
83
|
-
* result.match({
|
|
84
|
-
* ok: async (iter) => {
|
|
85
|
-
* const errors = await iter
|
|
86
|
-
* .filter(line => line.includes('ERROR'))
|
|
87
|
-
* .take(100)
|
|
88
|
-
* .collect();
|
|
89
|
-
* },
|
|
90
|
-
* err: (e) => console.error(e)
|
|
91
|
-
* });
|
|
92
|
-
*/
|
|
93
|
-
async function asyncIterLines(filepath) {
|
|
94
|
-
try {
|
|
95
|
-
await fs.promises.access(filepath, fs.constants.R_OK);
|
|
96
|
-
} catch (error) {
|
|
97
|
-
if (error instanceof Error) return require_async_iter.Err(`Failed to access file '${filepath}': ${error.message}`);
|
|
98
|
-
return require_async_iter.Err(`Failed to access file '${filepath}': ${String(error)}`);
|
|
99
|
-
}
|
|
100
|
-
return require_async_iter.Ok(require_async_iter.asyncIter((async function* () {
|
|
101
|
-
const fileStream = fs.createReadStream(filepath, { encoding: "utf-8" });
|
|
102
|
-
const rl = readline.createInterface({
|
|
103
|
-
input: fileStream,
|
|
104
|
-
crlfDelay: Infinity
|
|
105
|
-
});
|
|
106
|
-
try {
|
|
107
|
-
for await (const line of rl) yield line;
|
|
108
|
-
} finally {
|
|
109
|
-
rl.close();
|
|
110
|
-
fileStream.destroy();
|
|
111
|
-
}
|
|
112
|
-
})()));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
//#endregion
|
|
116
|
-
exports.asyncIterLines = asyncIterLines;
|
|
117
|
-
exports.iterLinesSync = iterLinesSync;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=require(`./async-iter-BY_bNd1c.cjs`);let l=require(`fs`);l=s(l);let u=require(`readline`);u=s(u);function d(e){try{let t=l.readFileSync(e,`utf-8`).split(`
|
|
2
|
+
`);return t.length>0&&t[t.length-1]===``&&t.pop(),c.f(c.s(t))}catch(t){return t instanceof Error?c.u(`Failed to read file '${e}': ${t.message}`):c.u(`Failed to read file '${e}': ${String(t)}`)}}async function f(e){try{await l.promises.access(e,l.constants.R_OK)}catch(t){return t instanceof Error?c.u(`Failed to access file '${e}': ${t.message}`):c.u(`Failed to access file '${e}': ${String(t)}`)}return c.f(c.n((async function*(){let t=l.createReadStream(e,{encoding:`utf-8`}),n=u.createInterface({input:t,crlfDelay:1/0});try{for await(let e of n)yield e}finally{n.close(),t.destroy()}})()))}exports.asyncIterLines=f,exports.iterLinesSync=d;
|
|
118
3
|
//# sourceMappingURL=node.cjs.map
|
package/dist/node.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.cjs","names":["Ok","iter","Err","asyncIter"],"sources":["../src/node.ts"],"sourcesContent":["/**\n * Node.js-specific utilities for rustlike.\n *\n * This module contains functions that depend on Node.js built-in modules\n * (fs, readline) and should only be imported in Node.js environments.\n * Browser and edge runtime consumers should use the main 'rustlike' entry point.\n *\n * Import from 'rustlike/node' to access these functions.\n */\n\nimport * as fs from \"fs\";\nimport * as readline from \"readline\";\nimport { Result, Ok, Err } from \"./core\";\nimport { iter } from \"./iter\";\nimport { asyncIter } from \"./async-iter\";\nimport type { Iter } from \"./iter\";\nimport type { AsyncIter } from \"./async-iter\";\n\n// ============================================================================\n// File Reading (Sync)\n// ============================================================================\n\n/**\n * Create an Iter that lazily reads lines from a file.\n * Uses Node.js fs.readFileSync but yields lines lazily via generator.\n *\n * Note: This reads the entire file into memory but yields lines lazily.\n * For truly streaming line-by-line reading, use asyncIterLines.\n *\n * @param filepath - Path to the file to read\n * @returns Result with Iter<string> on success, error message on failure\n *\n * @example\n * const lines = iterLinesSync('data.txt');\n * lines.match({\n * ok: (iter) => iter.skip(1).map(parseLine).collect(),\n * err: (e) => console.error(e)\n * });\n */\nexport function iterLinesSync(filepath: string): Result<Iter<string>, string> {\n try {\n const content = fs.readFileSync(filepath, \"utf-8\");\n const lines = content.split(\"\\n\");\n // Remove trailing empty line if file ends with newline\n if (lines.length > 0 && lines[lines.length - 1] === \"\") {\n lines.pop();\n }\n return Ok(iter(lines));\n } catch (error) {\n if (error instanceof Error) {\n return Err(`Failed to read file '${filepath}': ${error.message}`);\n }\n return Err(`Failed to read file '${filepath}': ${String(error)}`);\n }\n}\n\n// ============================================================================\n// File Reading (Async)\n// ============================================================================\n\n/**\n * Create an AsyncIter that reads lines from a file using streaming.\n * Truly memory-efficient - reads lines on-demand without loading entire file.\n *\n * Uses Node.js readline with createReadStream for efficient streaming.\n *\n * @param filepath - Path to the file to read\n * @returns Promise of Result with AsyncIter<string> on success, error message on failure\n *\n * @example\n * const result = await asyncIterLines('large-log.txt');\n * result.match({\n * ok: async (iter) => {\n * const errors = await iter\n * .filter(line => line.includes('ERROR'))\n * .take(100)\n * .collect();\n * },\n * err: (e) => console.error(e)\n * });\n */\nexport async function asyncIterLines(filepath: string): Promise<Result<AsyncIter<string>, string>> {\n // Check if file exists first\n try {\n await fs.promises.access(filepath, fs.constants.R_OK);\n } catch (error) {\n if (error instanceof Error) {\n return Err(`Failed to access file '${filepath}': ${error.message}`);\n }\n return Err(`Failed to access file '${filepath}': ${String(error)}`);\n }\n\n // Create the async iterator using readline\n const asyncIterator = (async function* () {\n const fileStream = fs.createReadStream(filepath, { encoding: \"utf-8\" });\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity, // Handle both \\n and \\r\\n\n });\n\n try {\n for await (const line of rl) {\n yield line;\n }\n } finally {\n rl.close();\n fileStream.destroy();\n }\n })();\n\n return Ok(asyncIter(asyncIterator));\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.cjs","names":["Ok","iter","Err","asyncIter"],"sources":["../src/node.ts"],"sourcesContent":["/**\n * Node.js-specific utilities for rustlike.\n *\n * This module contains functions that depend on Node.js built-in modules\n * (fs, readline) and should only be imported in Node.js environments.\n * Browser and edge runtime consumers should use the main 'rustlike' entry point.\n *\n * Import from 'rustlike/node' to access these functions.\n */\n\nimport * as fs from \"fs\";\nimport * as readline from \"readline\";\nimport { Result, Ok, Err } from \"./core\";\nimport { iter } from \"./iter\";\nimport { asyncIter } from \"./async-iter\";\nimport type { Iter } from \"./iter\";\nimport type { AsyncIter } from \"./async-iter\";\n\n// ============================================================================\n// File Reading (Sync)\n// ============================================================================\n\n/**\n * Create an Iter that lazily reads lines from a file.\n * Uses Node.js fs.readFileSync but yields lines lazily via generator.\n *\n * Note: This reads the entire file into memory but yields lines lazily.\n * For truly streaming line-by-line reading, use asyncIterLines.\n *\n * @param filepath - Path to the file to read\n * @returns Result with Iter<string> on success, error message on failure\n *\n * @example\n * const lines = iterLinesSync('data.txt');\n * lines.match({\n * ok: (iter) => iter.skip(1).map(parseLine).collect(),\n * err: (e) => console.error(e)\n * });\n */\nexport function iterLinesSync(filepath: string): Result<Iter<string>, string> {\n try {\n const content = fs.readFileSync(filepath, \"utf-8\");\n const lines = content.split(\"\\n\");\n // Remove trailing empty line if file ends with newline\n if (lines.length > 0 && lines[lines.length - 1] === \"\") {\n lines.pop();\n }\n return Ok(iter(lines));\n } catch (error) {\n if (error instanceof Error) {\n return Err(`Failed to read file '${filepath}': ${error.message}`);\n }\n return Err(`Failed to read file '${filepath}': ${String(error)}`);\n }\n}\n\n// ============================================================================\n// File Reading (Async)\n// ============================================================================\n\n/**\n * Create an AsyncIter that reads lines from a file using streaming.\n * Truly memory-efficient - reads lines on-demand without loading entire file.\n *\n * Uses Node.js readline with createReadStream for efficient streaming.\n *\n * @param filepath - Path to the file to read\n * @returns Promise of Result with AsyncIter<string> on success, error message on failure\n *\n * @example\n * const result = await asyncIterLines('large-log.txt');\n * result.match({\n * ok: async (iter) => {\n * const errors = await iter\n * .filter(line => line.includes('ERROR'))\n * .take(100)\n * .collect();\n * },\n * err: (e) => console.error(e)\n * });\n */\nexport async function asyncIterLines(filepath: string): Promise<Result<AsyncIter<string>, string>> {\n // Check if file exists first\n try {\n await fs.promises.access(filepath, fs.constants.R_OK);\n } catch (error) {\n if (error instanceof Error) {\n return Err(`Failed to access file '${filepath}': ${error.message}`);\n }\n return Err(`Failed to access file '${filepath}': ${String(error)}`);\n }\n\n // Create the async iterator using readline\n const asyncIterator = (async function* () {\n const fileStream = fs.createReadStream(filepath, { encoding: \"utf-8\" });\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity, // Handle both \\n and \\r\\n\n });\n\n try {\n for await (const line of rl) {\n yield line;\n }\n } finally {\n rl.close();\n fileStream.destroy();\n }\n })();\n\n return Ok(asyncIter(asyncIterator));\n}\n"],"mappings":"0oBAuCA,SAAgB,EAAc,EAAgD,CAC5E,GAAI,CAEF,IAAM,EADU,EAAG,aAAa,EAAU,QAAQ,CAC5B,MAAM;EAAK,CAKjC,OAHI,EAAM,OAAS,GAAK,EAAM,EAAM,OAAS,KAAO,IAClD,EAAM,KAAK,CAENA,EAAAA,EAAGC,EAAAA,EAAK,EAAM,CAAC,OACf,EAAO,CAId,OAHI,aAAiB,MACZC,EAAAA,EAAI,wBAAwB,EAAS,KAAK,EAAM,UAAU,CAE5DA,EAAAA,EAAI,wBAAwB,EAAS,KAAK,OAAO,EAAM,GAAG,EA6BrE,eAAsB,EAAe,EAA8D,CAEjG,GAAI,CACF,MAAM,EAAG,SAAS,OAAO,EAAU,EAAG,UAAU,KAAK,OAC9C,EAAO,CAId,OAHI,aAAiB,MACZA,EAAAA,EAAI,0BAA0B,EAAS,KAAK,EAAM,UAAU,CAE9DA,EAAAA,EAAI,0BAA0B,EAAS,KAAK,OAAO,EAAM,GAAG,CAqBrE,OAAOF,EAAAA,EAAGG,EAAAA,GAjBa,iBAAmB,CACxC,IAAM,EAAa,EAAG,iBAAiB,EAAU,CAAE,SAAU,QAAS,CAAC,CACjE,EAAK,EAAS,gBAAgB,CAClC,MAAO,EACP,UAAW,IACZ,CAAC,CAEF,GAAI,CACF,UAAW,IAAM,KAAQ,EACvB,MAAM,SAEA,CACR,EAAG,OAAO,CACV,EAAW,SAAS,KAEpB,CAE8B,CAAC"}
|
package/dist/node.mjs
CHANGED
|
@@ -1,87 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import * as readline from "readline";
|
|
4
|
-
|
|
5
|
-
//#region src/node.ts
|
|
6
|
-
/**
|
|
7
|
-
* Node.js-specific utilities for rustlike.
|
|
8
|
-
*
|
|
9
|
-
* This module contains functions that depend on Node.js built-in modules
|
|
10
|
-
* (fs, readline) and should only be imported in Node.js environments.
|
|
11
|
-
* Browser and edge runtime consumers should use the main 'rustlike' entry point.
|
|
12
|
-
*
|
|
13
|
-
* Import from 'rustlike/node' to access these functions.
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Create an Iter that lazily reads lines from a file.
|
|
17
|
-
* Uses Node.js fs.readFileSync but yields lines lazily via generator.
|
|
18
|
-
*
|
|
19
|
-
* Note: This reads the entire file into memory but yields lines lazily.
|
|
20
|
-
* For truly streaming line-by-line reading, use asyncIterLines.
|
|
21
|
-
*
|
|
22
|
-
* @param filepath - Path to the file to read
|
|
23
|
-
* @returns Result with Iter<string> on success, error message on failure
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* const lines = iterLinesSync('data.txt');
|
|
27
|
-
* lines.match({
|
|
28
|
-
* ok: (iter) => iter.skip(1).map(parseLine).collect(),
|
|
29
|
-
* err: (e) => console.error(e)
|
|
30
|
-
* });
|
|
31
|
-
*/
|
|
32
|
-
function iterLinesSync(filepath) {
|
|
33
|
-
try {
|
|
34
|
-
const lines = fs.readFileSync(filepath, "utf-8").split("\n");
|
|
35
|
-
if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
|
|
36
|
-
return Ok(iter(lines));
|
|
37
|
-
} catch (error) {
|
|
38
|
-
if (error instanceof Error) return Err(`Failed to read file '${filepath}': ${error.message}`);
|
|
39
|
-
return Err(`Failed to read file '${filepath}': ${String(error)}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Create an AsyncIter that reads lines from a file using streaming.
|
|
44
|
-
* Truly memory-efficient - reads lines on-demand without loading entire file.
|
|
45
|
-
*
|
|
46
|
-
* Uses Node.js readline with createReadStream for efficient streaming.
|
|
47
|
-
*
|
|
48
|
-
* @param filepath - Path to the file to read
|
|
49
|
-
* @returns Promise of Result with AsyncIter<string> on success, error message on failure
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* const result = await asyncIterLines('large-log.txt');
|
|
53
|
-
* result.match({
|
|
54
|
-
* ok: async (iter) => {
|
|
55
|
-
* const errors = await iter
|
|
56
|
-
* .filter(line => line.includes('ERROR'))
|
|
57
|
-
* .take(100)
|
|
58
|
-
* .collect();
|
|
59
|
-
* },
|
|
60
|
-
* err: (e) => console.error(e)
|
|
61
|
-
* });
|
|
62
|
-
*/
|
|
63
|
-
async function asyncIterLines(filepath) {
|
|
64
|
-
try {
|
|
65
|
-
await fs.promises.access(filepath, fs.constants.R_OK);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
if (error instanceof Error) return Err(`Failed to access file '${filepath}': ${error.message}`);
|
|
68
|
-
return Err(`Failed to access file '${filepath}': ${String(error)}`);
|
|
69
|
-
}
|
|
70
|
-
return Ok(asyncIter((async function* () {
|
|
71
|
-
const fileStream = fs.createReadStream(filepath, { encoding: "utf-8" });
|
|
72
|
-
const rl = readline.createInterface({
|
|
73
|
-
input: fileStream,
|
|
74
|
-
crlfDelay: Infinity
|
|
75
|
-
});
|
|
76
|
-
try {
|
|
77
|
-
for await (const line of rl) yield line;
|
|
78
|
-
} finally {
|
|
79
|
-
rl.close();
|
|
80
|
-
fileStream.destroy();
|
|
81
|
-
}
|
|
82
|
-
})()));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
//#endregion
|
|
86
|
-
export { asyncIterLines, iterLinesSync };
|
|
1
|
+
import{f as e,n as t,s as n,u as r}from"./async-iter-D51Pm8tA.mjs";import*as i from"fs";import*as a from"readline";function o(t){try{let r=i.readFileSync(t,`utf-8`).split(`
|
|
2
|
+
`);return r.length>0&&r[r.length-1]===``&&r.pop(),e(n(r))}catch(e){return e instanceof Error?r(`Failed to read file '${t}': ${e.message}`):r(`Failed to read file '${t}': ${String(e)}`)}}async function s(n){try{await i.promises.access(n,i.constants.R_OK)}catch(e){return e instanceof Error?r(`Failed to access file '${n}': ${e.message}`):r(`Failed to access file '${n}': ${String(e)}`)}return e(t((async function*(){let e=i.createReadStream(n,{encoding:`utf-8`}),t=a.createInterface({input:e,crlfDelay:1/0});try{for await(let e of t)yield e}finally{t.close(),e.destroy()}})()))}export{s as asyncIterLines,o as iterLinesSync};
|
|
87
3
|
//# sourceMappingURL=node.mjs.map
|
package/dist/node.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.mjs","names":[],"sources":["../src/node.ts"],"sourcesContent":["/**\n * Node.js-specific utilities for rustlike.\n *\n * This module contains functions that depend on Node.js built-in modules\n * (fs, readline) and should only be imported in Node.js environments.\n * Browser and edge runtime consumers should use the main 'rustlike' entry point.\n *\n * Import from 'rustlike/node' to access these functions.\n */\n\nimport * as fs from \"fs\";\nimport * as readline from \"readline\";\nimport { Result, Ok, Err } from \"./core\";\nimport { iter } from \"./iter\";\nimport { asyncIter } from \"./async-iter\";\nimport type { Iter } from \"./iter\";\nimport type { AsyncIter } from \"./async-iter\";\n\n// ============================================================================\n// File Reading (Sync)\n// ============================================================================\n\n/**\n * Create an Iter that lazily reads lines from a file.\n * Uses Node.js fs.readFileSync but yields lines lazily via generator.\n *\n * Note: This reads the entire file into memory but yields lines lazily.\n * For truly streaming line-by-line reading, use asyncIterLines.\n *\n * @param filepath - Path to the file to read\n * @returns Result with Iter<string> on success, error message on failure\n *\n * @example\n * const lines = iterLinesSync('data.txt');\n * lines.match({\n * ok: (iter) => iter.skip(1).map(parseLine).collect(),\n * err: (e) => console.error(e)\n * });\n */\nexport function iterLinesSync(filepath: string): Result<Iter<string>, string> {\n try {\n const content = fs.readFileSync(filepath, \"utf-8\");\n const lines = content.split(\"\\n\");\n // Remove trailing empty line if file ends with newline\n if (lines.length > 0 && lines[lines.length - 1] === \"\") {\n lines.pop();\n }\n return Ok(iter(lines));\n } catch (error) {\n if (error instanceof Error) {\n return Err(`Failed to read file '${filepath}': ${error.message}`);\n }\n return Err(`Failed to read file '${filepath}': ${String(error)}`);\n }\n}\n\n// ============================================================================\n// File Reading (Async)\n// ============================================================================\n\n/**\n * Create an AsyncIter that reads lines from a file using streaming.\n * Truly memory-efficient - reads lines on-demand without loading entire file.\n *\n * Uses Node.js readline with createReadStream for efficient streaming.\n *\n * @param filepath - Path to the file to read\n * @returns Promise of Result with AsyncIter<string> on success, error message on failure\n *\n * @example\n * const result = await asyncIterLines('large-log.txt');\n * result.match({\n * ok: async (iter) => {\n * const errors = await iter\n * .filter(line => line.includes('ERROR'))\n * .take(100)\n * .collect();\n * },\n * err: (e) => console.error(e)\n * });\n */\nexport async function asyncIterLines(filepath: string): Promise<Result<AsyncIter<string>, string>> {\n // Check if file exists first\n try {\n await fs.promises.access(filepath, fs.constants.R_OK);\n } catch (error) {\n if (error instanceof Error) {\n return Err(`Failed to access file '${filepath}': ${error.message}`);\n }\n return Err(`Failed to access file '${filepath}': ${String(error)}`);\n }\n\n // Create the async iterator using readline\n const asyncIterator = (async function* () {\n const fileStream = fs.createReadStream(filepath, { encoding: \"utf-8\" });\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity, // Handle both \\n and \\r\\n\n });\n\n try {\n for await (const line of rl) {\n yield line;\n }\n } finally {\n rl.close();\n fileStream.destroy();\n }\n })();\n\n return Ok(asyncIter(asyncIterator));\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.mjs","names":[],"sources":["../src/node.ts"],"sourcesContent":["/**\n * Node.js-specific utilities for rustlike.\n *\n * This module contains functions that depend on Node.js built-in modules\n * (fs, readline) and should only be imported in Node.js environments.\n * Browser and edge runtime consumers should use the main 'rustlike' entry point.\n *\n * Import from 'rustlike/node' to access these functions.\n */\n\nimport * as fs from \"fs\";\nimport * as readline from \"readline\";\nimport { Result, Ok, Err } from \"./core\";\nimport { iter } from \"./iter\";\nimport { asyncIter } from \"./async-iter\";\nimport type { Iter } from \"./iter\";\nimport type { AsyncIter } from \"./async-iter\";\n\n// ============================================================================\n// File Reading (Sync)\n// ============================================================================\n\n/**\n * Create an Iter that lazily reads lines from a file.\n * Uses Node.js fs.readFileSync but yields lines lazily via generator.\n *\n * Note: This reads the entire file into memory but yields lines lazily.\n * For truly streaming line-by-line reading, use asyncIterLines.\n *\n * @param filepath - Path to the file to read\n * @returns Result with Iter<string> on success, error message on failure\n *\n * @example\n * const lines = iterLinesSync('data.txt');\n * lines.match({\n * ok: (iter) => iter.skip(1).map(parseLine).collect(),\n * err: (e) => console.error(e)\n * });\n */\nexport function iterLinesSync(filepath: string): Result<Iter<string>, string> {\n try {\n const content = fs.readFileSync(filepath, \"utf-8\");\n const lines = content.split(\"\\n\");\n // Remove trailing empty line if file ends with newline\n if (lines.length > 0 && lines[lines.length - 1] === \"\") {\n lines.pop();\n }\n return Ok(iter(lines));\n } catch (error) {\n if (error instanceof Error) {\n return Err(`Failed to read file '${filepath}': ${error.message}`);\n }\n return Err(`Failed to read file '${filepath}': ${String(error)}`);\n }\n}\n\n// ============================================================================\n// File Reading (Async)\n// ============================================================================\n\n/**\n * Create an AsyncIter that reads lines from a file using streaming.\n * Truly memory-efficient - reads lines on-demand without loading entire file.\n *\n * Uses Node.js readline with createReadStream for efficient streaming.\n *\n * @param filepath - Path to the file to read\n * @returns Promise of Result with AsyncIter<string> on success, error message on failure\n *\n * @example\n * const result = await asyncIterLines('large-log.txt');\n * result.match({\n * ok: async (iter) => {\n * const errors = await iter\n * .filter(line => line.includes('ERROR'))\n * .take(100)\n * .collect();\n * },\n * err: (e) => console.error(e)\n * });\n */\nexport async function asyncIterLines(filepath: string): Promise<Result<AsyncIter<string>, string>> {\n // Check if file exists first\n try {\n await fs.promises.access(filepath, fs.constants.R_OK);\n } catch (error) {\n if (error instanceof Error) {\n return Err(`Failed to access file '${filepath}': ${error.message}`);\n }\n return Err(`Failed to access file '${filepath}': ${String(error)}`);\n }\n\n // Create the async iterator using readline\n const asyncIterator = (async function* () {\n const fileStream = fs.createReadStream(filepath, { encoding: \"utf-8\" });\n const rl = readline.createInterface({\n input: fileStream,\n crlfDelay: Infinity, // Handle both \\n and \\r\\n\n });\n\n try {\n for await (const line of rl) {\n yield line;\n }\n } finally {\n rl.close();\n fileStream.destroy();\n }\n })();\n\n return Ok(asyncIter(asyncIterator));\n}\n"],"mappings":"mHAuCA,SAAgB,EAAc,EAAgD,CAC5E,GAAI,CAEF,IAAM,EADU,EAAG,aAAa,EAAU,QAAQ,CAC5B,MAAM;EAAK,CAKjC,OAHI,EAAM,OAAS,GAAK,EAAM,EAAM,OAAS,KAAO,IAClD,EAAM,KAAK,CAEN,EAAG,EAAK,EAAM,CAAC,OACf,EAAO,CAId,OAHI,aAAiB,MACZ,EAAI,wBAAwB,EAAS,KAAK,EAAM,UAAU,CAE5D,EAAI,wBAAwB,EAAS,KAAK,OAAO,EAAM,GAAG,EA6BrE,eAAsB,EAAe,EAA8D,CAEjG,GAAI,CACF,MAAM,EAAG,SAAS,OAAO,EAAU,EAAG,UAAU,KAAK,OAC9C,EAAO,CAId,OAHI,aAAiB,MACZ,EAAI,0BAA0B,EAAS,KAAK,EAAM,UAAU,CAE9D,EAAI,0BAA0B,EAAS,KAAK,OAAO,EAAM,GAAG,CAqBrE,OAAO,EAAG,GAjBa,iBAAmB,CACxC,IAAM,EAAa,EAAG,iBAAiB,EAAU,CAAE,SAAU,QAAS,CAAC,CACjE,EAAK,EAAS,gBAAgB,CAClC,MAAO,EACP,UAAW,IACZ,CAAC,CAEF,GAAI,CACF,UAAW,IAAM,KAAQ,EACvB,MAAM,SAEA,CACR,EAAG,OAAO,CACV,EAAW,SAAS,KAEpB,CAE8B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dangayle/rustlike",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"repository": {
|
|
5
|
-
"type": "git",
|
|
6
|
-
"url": "git+https://github.com/dangayle/rustlike.git"
|
|
7
|
-
},
|
|
8
|
-
"homepage": "https://github.com/dangayle/rustlike#readme",
|
|
9
|
-
"bugs": {
|
|
10
|
-
"url": "https://github.com/dangayle/rustlike/issues"
|
|
11
|
-
},
|
|
12
|
-
"publishConfig": {
|
|
13
|
-
"access": "public"
|
|
14
|
-
},
|
|
3
|
+
"version": "0.1.1",
|
|
15
4
|
"description": "TypeScript utilities for writing Rust-like code: Result, Option, exhaustive matching, and immutability helpers",
|
|
16
5
|
"keywords": [
|
|
17
6
|
"functional",
|
|
@@ -22,8 +11,16 @@
|
|
|
22
11
|
"rust",
|
|
23
12
|
"typescript"
|
|
24
13
|
],
|
|
14
|
+
"homepage": "https://github.com/dangayle/rustlike#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/dangayle/rustlike/issues"
|
|
17
|
+
},
|
|
25
18
|
"license": "MIT",
|
|
26
19
|
"author": "Dan Gayle <dangayle@gmail.com>",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/dangayle/rustlike.git"
|
|
23
|
+
},
|
|
27
24
|
"files": [
|
|
28
25
|
"dist"
|
|
29
26
|
],
|
|
@@ -53,15 +50,8 @@
|
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
52
|
},
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"@vitest/coverage-v8": "^4.0.18",
|
|
59
|
-
"oxfmt": "^0.36.0",
|
|
60
|
-
"oxlint": "^1.51.0",
|
|
61
|
-
"oxlint-tsgolint": "^0.16.0",
|
|
62
|
-
"tsdown": "^0.20.3",
|
|
63
|
-
"typescript": "^5.3.0",
|
|
64
|
-
"vitest": "^4.0.18"
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
65
55
|
},
|
|
66
56
|
"scripts": {
|
|
67
57
|
"build": "tsdown && pnpm -C packages/eslint-plugin-rustlike build",
|
|
@@ -75,6 +65,26 @@
|
|
|
75
65
|
"lint:fix": "oxlint --fix src/ examples/",
|
|
76
66
|
"typecheck": "tsc --noEmit",
|
|
77
67
|
"fmt": "oxfmt",
|
|
78
|
-
"fmt:check": "oxfmt --check"
|
|
68
|
+
"fmt:check": "oxfmt --check",
|
|
69
|
+
"prepublishOnly": "pnpm run build",
|
|
70
|
+
"release:patch": "node scripts/release.mjs patch",
|
|
71
|
+
"release:minor": "node scripts/release.mjs minor",
|
|
72
|
+
"release:major": "node scripts/release.mjs major"
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@types/node": "^25.3.3",
|
|
76
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
77
|
+
"oxfmt": "^0.36.0",
|
|
78
|
+
"oxlint": "^1.51.0",
|
|
79
|
+
"oxlint-tsgolint": "^0.16.0",
|
|
80
|
+
"tsdown": "^0.20.3",
|
|
81
|
+
"typescript": "^5.3.0",
|
|
82
|
+
"vitest": "^4.0.18"
|
|
83
|
+
},
|
|
84
|
+
"packageManager": "pnpm@10.22.0",
|
|
85
|
+
"pnpm": {
|
|
86
|
+
"overrides": {
|
|
87
|
+
"rollup": ">=4.59.0"
|
|
88
|
+
}
|
|
79
89
|
}
|
|
80
|
-
}
|
|
90
|
+
}
|