iterable-string-interceptor 2.2.3 → 2.3.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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2018-2022 by arlac77
1
+ Copyright (c) 2018-2024 by arlac77
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  [![npm](https://img.shields.io/npm/v/iterable-string-interceptor.svg)](https://www.npmjs.com/package/iterable-string-interceptor)
2
2
  [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
3
- [![Open Bundle](https://bundlejs.com/badge-light.svg)](https://bundlejs.com/?q=iterable-string-interceptor)
3
+ [![Typed with TypeScript](https://flat.badgen.net/badge/icon/Typed?icon=typescript\&label\&labelColor=blue\&color=555555)](https://typescriptlang.org)
4
+ [![bundlejs](https://deno.bundlejs.com/?q=iterable-string-interceptor\&badge=detailed)](https://bundlejs.com/?q=iterable-string-interceptor)
4
5
  [![downloads](http://img.shields.io/npm/dm/iterable-string-interceptor.svg?style=flat-square)](https://npmjs.org/package/iterable-string-interceptor)
5
6
  [![GitHub Issues](https://img.shields.io/github/issues/arlac77/iterable-string-interceptor.svg?style=flat-square)](https://github.com/arlac77/iterable-string-interceptor/issues)
6
7
  [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Farlac77%2Fiterable-string-interceptor%2Fbadge\&style=flat)](https://actions-badge.atrox.dev/arlac77/iterable-string-interceptor/goto)
@@ -57,7 +58,7 @@ for await (const chunk of iterableStringInterceptor(createReadStream('aFile', {
57
58
 
58
59
  ## ExpressionTransformer
59
60
 
60
- Type: ()
61
+ Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
61
62
 
62
63
  ### Parameters
63
64
 
@@ -68,13 +69,13 @@ Type: ()
68
69
  * `leadIn` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression entry sequence
69
70
  * `leadOut` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression exit sequence
70
71
 
71
- Returns **Iterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** transformed source
72
+ Returns **AsyncIterator<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** transformed source
72
73
 
73
74
  ## EarlyConsumerCallback
74
75
 
75
76
  Will be called from the ExpressionTransformer if the given remainder needs to be altered.
76
77
 
77
- Type: ()
78
+ Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
78
79
 
79
80
  ### Parameters
80
81
 
@@ -92,7 +93,7 @@ and asking a transformer for a replacement iterable string.
92
93
  * `leadIn` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression entry sequence (optional, default `"{{"`)
93
94
  * `leadOut` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression exit sequence (optional, default `"}}"`)
94
95
 
95
- Returns **Iterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** transformed source
96
+ Returns **AsyncIterator<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** transformed source
96
97
 
97
98
  # install
98
99
 
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @typedef {Function} ExpressionTransformer
3
+ * @param {string} expression detected expression without leadIn / leadOut
4
+ * @param {string} remainder chunk after leadOut
5
+ * @param {Iterable<string>} source original source
6
+ * @param {EarlyConsumerCallback} cb to be called if remainder has changed
7
+ * @param {string} leadIn expression entry sequence
8
+ * @param {string} leadOut expression exit sequence
9
+ * @return {AsyncIterable<string>} transformed source
10
+ */
11
+ /**
12
+ * Will be called from the ExpressionTransformer if the given remainder needs to be altered.
13
+ * @typedef {Function} EarlyConsumerCallback
14
+ * @param {string} remainder new remainder to be used by iterableStringInterceptor
15
+ */
16
+ /**
17
+ * Intercept into a async iterable string source, detecting lead in/outs like '{{' and '}}'
18
+ * and asking a transformer for a replacement iterable string.
19
+ * @param {Iterable<string>} source
20
+ * @param {ExpressionTransformer} transform
21
+ * @param {string} leadIn expression entry sequence
22
+ * @param {string} leadOut expression exit sequence
23
+ * @return {AsyncIterable<string>} transformed source
24
+ */
25
+ export function iterableStringInterceptor(source: Iterable<string>, transform: ExpressionTransformer, leadIn?: string, leadOut?: string): AsyncIterable<string>;
26
+ export type ExpressionTransformer = Function;
27
+ /**
28
+ * Will be called from the ExpressionTransformer if the given remainder needs to be altered.
29
+ */
30
+ export type EarlyConsumerCallback = Function;
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "iterable-string-interceptor",
3
- "version": "2.2.3",
3
+ "version": "2.3.0",
4
4
  "publishConfig": {
5
- "access": "public"
5
+ "access": "public",
6
+ "provenance": true
6
7
  },
7
- "sideEffects": false,
8
8
  "exports": {
9
- ".": "./src/iterable-string-interceptor.mjs"
9
+ ".": {
10
+ "types": "./dist/iterable-string-interceptor.d.mts",
11
+ "default": "./src/iterable-string-interceptor.mjs"
12
+ }
10
13
  },
11
14
  "description": "Intercept iterable string - backbone for template engines",
12
15
  "keywords": [
@@ -21,27 +24,30 @@
21
24
  ],
22
25
  "license": "BSD-2-Clause",
23
26
  "scripts": {
27
+ "prepare": "tsc --allowJs --declaration --emitDeclarationOnly --declarationDir dist -t esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs",
24
28
  "test": "npm run test:browser-ava && npm run test:ava",
25
- "test:ava": "ava --timeout 2m tests/*-ava.mjs tests/*-ava-node.mjs",
29
+ "test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
26
30
  "test:browser-ava": "browser-ava --headless --no-keep-open tests/*-ava.mjs tests/*-ava-browser.mjs",
27
- "cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 2m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
31
+ "cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
28
32
  "docs": "documentation readme --section=API ./src/**/*.mjs",
29
- "lint": "npm run lint:docs",
30
- "lint:docs": "documentation lint ./src/**/*.mjs"
33
+ "lint": "npm run lint:docs && npm run lint:tsc",
34
+ "lint:docs": "documentation lint ./src/**/*.mjs",
35
+ "lint:tsc": "tsc --allowJs --checkJs --noEmit -t esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
31
36
  },
32
37
  "devDependencies": {
33
- "ava": "^5.1.0",
34
- "browser-ava": "^1.3.13",
35
- "c8": "^7.12.0",
36
- "documentation": "^14.0.1",
37
- "semantic-release": "^19.0.5"
38
+ "ava": "^6.1.1",
39
+ "browser-ava": "^2.1.12",
40
+ "c8": "^9.1.0",
41
+ "documentation": "^14.0.3",
42
+ "semantic-release": "^23.0.2",
43
+ "typescript": "^5.3.3"
38
44
  },
39
45
  "engines": {
40
- "node": ">=16.19.0"
46
+ "node": ">=16.20.2"
41
47
  },
42
48
  "repository": {
43
49
  "type": "git",
44
- "url": "https://github.com/arlac77/iterable-string-interceptor.git"
50
+ "url": "git+https://github.com/arlac77/iterable-string-interceptor.git"
45
51
  },
46
52
  "bugs": {
47
53
  "url": "https://github.com/arlac77/iterable-string-interceptor/issues"
@@ -51,7 +57,8 @@
51
57
  "inheritFrom": [
52
58
  "arlac77/template-arlac77-github",
53
59
  "arlac77/template-browser-ava",
54
- "arlac77/template-esm-only"
60
+ "arlac77/template-javascript-component",
61
+ "arlac77/template-typescript"
55
62
  ]
56
63
  }
57
64
  }
@@ -1,17 +1,17 @@
1
1
  /**
2
- * @typedef {()} ExpressionTransformer
2
+ * @typedef {Function} ExpressionTransformer
3
3
  * @param {string} expression detected expression without leadIn / leadOut
4
4
  * @param {string} remainder chunk after leadOut
5
5
  * @param {Iterable<string>} source original source
6
6
  * @param {EarlyConsumerCallback} cb to be called if remainder has changed
7
7
  * @param {string} leadIn expression entry sequence
8
8
  * @param {string} leadOut expression exit sequence
9
- * @return {Iterable<string>} transformed source
9
+ * @return {AsyncIterable<string>} transformed source
10
10
  */
11
11
 
12
12
  /**
13
13
  * Will be called from the ExpressionTransformer if the given remainder needs to be altered.
14
- * @typedef {()} EarlyConsumerCallback
14
+ * @typedef {Function} EarlyConsumerCallback
15
15
  * @param {string} remainder new remainder to be used by iterableStringInterceptor
16
16
  */
17
17
 
@@ -22,7 +22,7 @@
22
22
  * @param {ExpressionTransformer} transform
23
23
  * @param {string} leadIn expression entry sequence
24
24
  * @param {string} leadOut expression exit sequence
25
- * @return {Iterable<string>} transformed source
25
+ * @return {AsyncIterable<string>} transformed source
26
26
  */
27
27
  export async function* iterableStringInterceptor(
28
28
  source,
@@ -99,7 +99,7 @@ export async function* iterableStringInterceptor(
99
99
  }
100
100
  } while (chunk.length > 0);
101
101
  }
102
- if (buffer != undefined) {
102
+ if (buffer !== undefined) {
103
103
  yield buffer;
104
104
  }
105
105
  }