catenation 0.1.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 +21 -0
- package/README.md +26 -0
- package/index.cjs +17 -0
- package/index.d.ts +2 -0
- package/package.json +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 catenation contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# catenation
|
|
2
|
+
|
|
3
|
+
Lazily concatenate arrays, sets, strings, and generators without copying their contents. No dependencies.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install catenation
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
const {catenate} = require('catenation');
|
|
11
|
+
|
|
12
|
+
// consume sources in order without building an intermediate array.
|
|
13
|
+
for (const value of catenate([1, 2], new Set([3, 4]))) {
|
|
14
|
+
console.log(value);
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
ES modules can use `import {catenate} from 'catenation'`.
|
|
19
|
+
|
|
20
|
+
`catenate(...sources)` returns a single-use generator. Sources must be synchronous iterables; invalid arguments throw immediately. No sources produce an empty iterator. Strings yield Unicode code points. Nested arrays remain intact: this concatenates sources, rather than recursively flattening values.
|
|
21
|
+
|
|
22
|
+
Values are read only when requested, so mutations before consumption are visible. Infinite sources are supported, but later sources are reached only after earlier ones finish. Breaking out of a `for...of` loop closes the active source iterator; sources not yet reached are never opened. Source errors propagate to the consumer.
|
|
23
|
+
|
|
24
|
+
Requires Node.js 20 or later. TypeScript declarations are included. Run `npm test` from the source directory to check behavior.
|
|
25
|
+
|
|
26
|
+
MIT licensed.
|
package/index.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// validate sources without consuming them, then yield each one in order.
|
|
4
|
+
function catenate(...sources) {
|
|
5
|
+
for (const source of sources) {
|
|
6
|
+
if (source == null || typeof source[Symbol.iterator] !== 'function') {
|
|
7
|
+
throw new TypeError('each source must be a synchronous iterable');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// delegation also closes the active iterator when the caller stops early.
|
|
12
|
+
return (function* () {
|
|
13
|
+
for (const source of sources) yield* source;
|
|
14
|
+
})();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.catenate = catenate;
|
package/index.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "catenation",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Lazily concatenate synchronous iterables without copying their contents.",
|
|
5
|
+
"main": "index.cjs",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": ["index.cjs", "index.d.ts"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "node --test test.cjs",
|
|
10
|
+
"prepublishOnly": "npm test"
|
|
11
|
+
},
|
|
12
|
+
"keywords": ["iterable", "iterator", "concat", "generator", "lazy"],
|
|
13
|
+
"engines": {"node": ">=20"},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"publishConfig": {"access": "public", "registry": "https://registry.npmjs.org/"}
|
|
16
|
+
}
|