@thi.ng/transducers
Advanced tools
Comparing version 0.11.1 to 0.11.2
@@ -1,1 +0,16 @@ | ||
export declare function concat<T>(...inputs: Iterable<T>[]): IterableIterator<any>; | ||
/** | ||
* Yields iterator producing concatenation of given iterables. | ||
* Undefined & null inputs are silently ignored, however any | ||
* such values produced or contained in an input will remain. | ||
* | ||
* ``` | ||
* [...concat([1, 2, 3], null, [4, 5])] | ||
* // [ 1, 2, 3, 4, 5 ] | ||
* | ||
* [...concat([1, 2, 3, undefined], null, [4, 5])] | ||
* // [ 1, 2, 3, undefined, 4, 5 ] | ||
* ``` | ||
* | ||
* @param xs | ||
*/ | ||
export declare function concat<T>(...xs: Iterable<T>[]): IterableIterator<T>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ensure_iterable_1 = require("../func/ensure-iterable"); | ||
function* concat(...inputs) { | ||
let iter = inputs[Symbol.iterator](), v; | ||
while (((v = iter.next()), !v.done)) { | ||
if (v.value != null) { | ||
yield* ensure_iterable_1.ensureIterable(v.value); | ||
} | ||
/** | ||
* Yields iterator producing concatenation of given iterables. | ||
* Undefined & null inputs are silently ignored, however any | ||
* such values produced or contained in an input will remain. | ||
* | ||
* ``` | ||
* [...concat([1, 2, 3], null, [4, 5])] | ||
* // [ 1, 2, 3, 4, 5 ] | ||
* | ||
* [...concat([1, 2, 3, undefined], null, [4, 5])] | ||
* // [ 1, 2, 3, undefined, 4, 5 ] | ||
* ``` | ||
* | ||
* @param xs | ||
*/ | ||
function* concat(...xs) { | ||
for (let x of xs) { | ||
x != null && (yield* ensure_iterable_1.ensureIterable(x)); | ||
} | ||
} | ||
exports.concat = concat; |
@@ -0,1 +1,10 @@ | ||
/** | ||
* Yields iterator producing input in reverse order. | ||
* Important: Input MUST be finite. Unless an | ||
* ``` | ||
* [...tx.reverse("hello world")] | ||
* // [ "d", "l", "r", "o", "w", " ", "o", "l", "l", "e", "h" ] | ||
* ``` | ||
* @param input | ||
*/ | ||
export declare function reverse<T>(input: Iterable<T>): IterableIterator<any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const is_arraylike_1 = require("@thi.ng/checks/is-arraylike"); | ||
/** | ||
* Yields iterator producing input in reverse order. | ||
* Important: Input MUST be finite. Unless an | ||
* ``` | ||
* [...tx.reverse("hello world")] | ||
* // [ "d", "l", "r", "o", "w", " ", "o", "l", "l", "e", "h" ] | ||
* ``` | ||
* @param input | ||
*/ | ||
function* reverse(input) { | ||
if (!(input.constructor === Array || input.length !== undefined)) { | ||
if (!is_arraylike_1.isArrayLike(input)) { | ||
input = [...input]; | ||
@@ -6,0 +16,0 @@ } |
{ | ||
"name": "@thi.ng/transducers", | ||
"version": "0.11.1", | ||
"version": "0.11.2", | ||
"description": "Lightweight transducer implementations for ES6 / TypeScript", | ||
@@ -26,3 +26,4 @@ "main": "./index.js", | ||
"dependencies": { | ||
"@thi.ng/api": "^1.2.1" | ||
"@thi.ng/api": "^1.2.1", | ||
"@thi.ng/checks": "^1.1.1" | ||
}, | ||
@@ -29,0 +30,0 @@ "keywords": [ |
@@ -30,11 +30,11 @@ # @thi.ng/transducers | ||
Please see the [@thi.ng/iterators](https://github.com/thi-ng/iterators) & | ||
[@thi.ng/csp](https://github.com/thi-ng/csp) partner modules for related | ||
Please see the [@thi.ng/iterators](https://github.com/thi-ng/umbrella/tree/master/packages/iterators) & | ||
[@thi.ng/csp](https://github.com/thi-ng/umbrella/tree/master/packages/csp) partner modules for related | ||
functionality, supplementing features of this library. However, this lib has no | ||
dependencies on either of them. The only dependency is | ||
[@thi.ng/api](https://github.com/thi-ng/api) for re-using common types & | ||
[@thi.ng/api](https://github.com/thi-ng/umbrella/tree/master/packages/api) for re-using common types & | ||
interfaces. | ||
Having said this, since 0.8.0 this project largely supersedes the | ||
[@thi.ng/iterators](https://github.com/thi-ng/iterators) library for most use | ||
[@thi.ng/iterators](https://github.com/thi-ng/umbrella/tree/master/packages/iterators) library for most use | ||
cases and offers are more powerful API and potentially faster execution of | ||
@@ -41,0 +41,0 @@ composed transformations (due to lack of ES generator overheads). |
import { Transducer } from "../api"; | ||
/** | ||
* Stateful transducer. Decodes base64 chars into bytes. | ||
* Supports URL safe & unsafe flavors. | ||
*/ | ||
export declare function base64Decode(): Transducer<string, number>; | ||
/** | ||
* Stateful transducer. Encodes bytes into base64 chars. | ||
* Supports URL safe & unsafe flavors. Uses internal | ||
* buffer to store intermediate results and repeatedly | ||
* calls reducer to drain buffer whenever it's been filled. | ||
* | ||
* @param urlSafe | ||
* @param bufSize | ||
*/ | ||
export declare function base64Encode(urlSafe?: boolean, bufSize?: number): Transducer<number, string>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../func/comp"); | ||
const index_1 = require("../index"); | ||
const reduced_1 = require("../reduced"); | ||
const B64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
const B64_SAFE = B64_CHARS.substr(0, 62) + "-_"; | ||
/** | ||
* Stateful transducer. Decodes base64 chars into bytes. | ||
* Supports URL safe & unsafe flavors. | ||
*/ | ||
function base64Decode() { | ||
@@ -34,2 +37,11 @@ return (rfn) => { | ||
exports.base64Decode = base64Decode; | ||
/** | ||
* Stateful transducer. Encodes bytes into base64 chars. | ||
* Supports URL safe & unsafe flavors. Uses internal | ||
* buffer to store intermediate results and repeatedly | ||
* calls reducer to drain buffer whenever it's been filled. | ||
* | ||
* @param urlSafe | ||
* @param bufSize | ||
*/ | ||
function base64Encode(urlSafe = false, bufSize = 1024) { | ||
@@ -52,3 +64,3 @@ return ([init, complete, reduce]) => { | ||
} | ||
while (buf.length && !index_1.isReduced(acc)) { | ||
while (buf.length && !reduced_1.isReduced(acc)) { | ||
acc = reduce(acc, buf.shift()); | ||
@@ -75,3 +87,3 @@ } | ||
acc = reduce(acc, buf[i]); | ||
if (index_1.isReduced(acc)) { | ||
if (reduced_1.isReduced(acc)) { | ||
buf.length = 0; | ||
@@ -78,0 +90,0 @@ return acc; |
import { Transducer } from "../api"; | ||
/** | ||
* Stateful transducer. Ignores the actual input values, but | ||
* produces time measurements since last value processed, | ||
* e.g. for use in async usage contexts. | ||
* | ||
* ``` | ||
* // example using @thi.ng/rstream | ||
* rstream | ||
* .fromInterval(1000) | ||
* .subscribe( | ||
* rstream.trace(), | ||
* comp(benchmark(), movingAverage(60)) | ||
* ) | ||
* ``` | ||
*/ | ||
export declare function benchmark(): Transducer<any, number>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const comp_1 = require("../func/comp"); | ||
/** | ||
* Stateful transducer. Ignores the actual input values, but | ||
* produces time measurements since last value processed, | ||
* e.g. for use in async usage contexts. | ||
* | ||
* ``` | ||
* // example using @thi.ng/rstream | ||
* rstream | ||
* .fromInterval(1000) | ||
* .subscribe( | ||
* rstream.trace(), | ||
* comp(benchmark(), movingAverage(60)) | ||
* ) | ||
* ``` | ||
*/ | ||
function benchmark() { | ||
return (rfn) => { | ||
const r = rfn[2]; | ||
let prev; | ||
let prev = Date.now(); | ||
return comp_1.compR(rfn, (acc, _) => { | ||
let t = Date.now(), x = prev ? t - prev : 0; | ||
let t = Date.now(), x = t - prev; | ||
prev = t; | ||
@@ -11,0 +26,0 @@ return r(acc, x); |
@@ -5,3 +5,3 @@ import { Transducer } from "../api"; | ||
* word size (default 8) and order (MSB first or LSB first). Only the | ||
* lower `wordSize` bits of each value are used. | ||
* lowest `wordSize` bits of each value are used (max 32). | ||
* | ||
@@ -11,2 +11,4 @@ * ``` | ||
* // [ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0 ] | ||
* [...iterator(comp(bits(8), partition(4)), [0xf0, 0xaa])] | ||
* // [ [ 1, 1, 1, 1 ], [ 0, 0, 0, 0 ], [ 1, 0, 1, 0 ], [ 1, 0, 1, 0 ] ] | ||
* ``` | ||
@@ -13,0 +15,0 @@ * |
@@ -8,3 +8,3 @@ "use strict"; | ||
* word size (default 8) and order (MSB first or LSB first). Only the | ||
* lower `wordSize` bits of each value are used. | ||
* lowest `wordSize` bits of each value are used (max 32). | ||
* | ||
@@ -14,2 +14,4 @@ * ``` | ||
* // [ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0 ] | ||
* [...iterator(comp(bits(8), partition(4)), [0xf0, 0xaa])] | ||
* // [ [ 1, 1, 1, 1 ], [ 0, 0, 0, 0 ], [ 1, 0, 1, 0 ], [ 1, 0, 1, 0 ] ] | ||
* ``` | ||
@@ -16,0 +18,0 @@ * |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116702
2498
2
+ Added@thi.ng/checks@^1.1.1