taraskevizer 9.3.4 → 10.0.0-alpha.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/README.md CHANGED
@@ -4,19 +4,19 @@
4
4
 
5
5
  With npm:
6
6
 
7
- ```bash
7
+ ```sh
8
8
  npm install taraskevizer
9
9
  ```
10
10
 
11
11
  With yarn:
12
12
 
13
- ```bash
13
+ ```sh
14
14
  yarn add taraskevizer
15
15
  ```
16
16
 
17
17
  With bun:
18
18
 
19
- ```bash
19
+ ```sh
20
20
  bun add taraskevizer
21
21
  ```
22
22
 
@@ -24,7 +24,6 @@ bun add taraskevizer
24
24
 
25
25
  ```js
26
26
  import {
27
- tarask,
28
27
  pipelines,
29
28
  TaraskConfig,
30
29
  htmlConfigOptions,
@@ -34,32 +33,32 @@ import {
34
33
  VARIATION,
35
34
  } from 'taraskevizer';
36
35
 
37
- tarask('планета', pipelines.tar);
36
+ pipelines.tarask('планета');
38
37
  // "плянэта"
39
38
 
39
+ // Explicit config declaration is recommended if it's used multiple times
40
40
  const cfg = new TaraskConfig({
41
41
  abc: alphabets.cyrillic,
42
42
  j: 'always',
43
43
  variations: 'first',
44
- wrapperDict: ansiColorWrappers,
44
+ wrappers: ansiColorWrappers,
45
45
  g: true,
46
46
  });
47
- tarask('планета і Гродна', pipelines.tar, cfg);
47
+ pipelines.tarask('планета і Гродна', cfg);
48
48
  // "пл\x1b[32mя\x1b[0mн\x1b[32mэ\x1b[0mта \x1b[32mй\x1b[0m \x1b[35mГорадня\x1b[0m"
49
49
 
50
- const htmlCfg = new TaraskConfig({
51
- abc: alphabets.latin,
52
- g: false,
50
+ pipelines.tarask('энергія планеты', {
53
51
  ...htmlConfigOptions,
52
+ abc: alphabets.latin,
53
+ g: false, // ignored, g matters for cyrillic alphabet only
54
54
  });
55
- tarask('энергія планеты', pipelines.tar, htmlCfg);
56
55
  // "en<tarF>erg</tarF>ija p<tarF>lan</tarF>ety"
57
56
 
58
57
  const latinWithJiCfg = new TaraskConfig({
59
58
  abc: alphabets.latinJi,
60
59
  });
61
60
 
62
- tarask('яна і іншыя', pipelines.abcOnly, latinWithJiCfg);
61
+ pipelines.alphabetic('яна і іншыя', latinWithJiCfg);
63
62
  // "jana j jinšyja"
64
63
  ```
65
64
 
@@ -111,25 +110,25 @@ Appears only if alphabet is cyrillic.
111
110
 
112
111
  With npm:
113
112
 
114
- ```bash
113
+ ```sh
115
114
  npm install -g taraskevizer
116
115
  ```
117
116
 
118
117
  With yarn:
119
118
 
120
- ```bash
119
+ ```sh
121
120
  yarn global add taraskevizer
122
121
  ```
123
122
 
124
123
  With bun:
125
124
 
126
- ```bash
125
+ ```sh
127
126
  bun add -g taraskevizer
128
127
  ```
129
128
 
130
129
  ## Usage
131
130
 
132
- ```bash
131
+ ```sh
133
132
  tarask [options] text
134
133
  ```
135
134
 
@@ -140,13 +139,13 @@ For usage examples and options use `--help` option
140
139
 
141
140
  With npm:
142
141
 
143
- ```bash
142
+ ```sh
144
143
  npx taraskevizer [options] text
145
144
  ```
146
145
 
147
146
  With bun:
148
147
 
149
- ```bash
148
+ ```sh
150
149
  bunx taraskevizer [options] text
151
150
  ```
152
151
 
package/dist/bin.js CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { dicts, TaraskConfig, tarask, pipelines, htmlConfigOptions, wrappers, } from './index.js';
2
+ import { dicts, TaraskConfig, pipelines, htmlConfigOptions, wrappers } from './index.js';
3
3
  const printWithPrefix = (msg) => {
4
4
  process.stdout.write("[taraskevizer]" + ' ' + msg + '\n');
5
5
  };
6
6
  process.argv.splice(0, 2);
7
7
  const checkForOptions = (options) => process.argv[0] && options.includes(process.argv[0].toLowerCase());
8
8
  if (checkForOptions(['-v', '--version'])) {
9
- printWithPrefix("9.3.4");
9
+ printWithPrefix("10.0.0-alpha.0");
10
10
  process.exit(0);
11
11
  }
12
12
  if (checkForOptions(['-h', '--help'])) {
@@ -63,7 +63,7 @@ let cfg = {
63
63
  variations: 'all',
64
64
  wrapperDict: wrappers.ansiColor,
65
65
  };
66
- let mode = 'tar';
66
+ let mode = 'tarask';
67
67
  const toHashTable = (dict) => {
68
68
  const result = {};
69
69
  for (const { 0: options, 1: callback } of dict)
@@ -143,7 +143,7 @@ const optionDict = toHashTable([
143
143
  [
144
144
  ['--alphabet-only', '-abc'],
145
145
  () => {
146
- mode = 'abc';
146
+ mode = 'alphabetic';
147
147
  },
148
148
  ],
149
149
  [
@@ -195,7 +195,7 @@ cfg = new TaraskConfig(isHtml
195
195
  wrapperDict: htmlConfigOptions.wrapperDict,
196
196
  }
197
197
  : cfg);
198
- if (process.stdout.write(tarask(text, pipelines[mode], cfg) + '\n')) {
198
+ if (process.stdout.write(pipelines[mode](text, cfg) + '\n')) {
199
199
  process.exit(0);
200
200
  }
201
201
  else {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * as dicts from './dict';
2
- export * from './tarask';
3
2
  export * from './config';
4
3
  export * as steps from './steps';
5
4
  export * as pipelines from './pipelines';
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * as dicts from './dict/index.js';
2
- export * from './tarask.js';
3
2
  export * from './config.js';
4
3
  export * as steps from './steps/index.js';
5
4
  export * as pipelines from './pipelines.js';
@@ -6,7 +6,7 @@ export const endZSoftenAndNiaBiaz = callableDict([
6
6
  // )
7
7
  // (?!{прыназоўнік})/
8
8
  [
9
- / не (?=[бвгджзйклмнпхрстфхцчшўьʼ]*.\u0301|[бвгджзйклмнпхрстфхцчшўьʼ]*[аеёіоуыэюя][бвгджзйклмнпхрстфхцчшўьʼ]* )(?!а[бд]?|б[ея]зь?|[дз]а|д?ля|дзеля|[нп]ад?|пр[аы]|празь?|у|церазь?)/g,
9
+ / не (?=[бвгджзйклмнпрстфхцчшўьʼ]*.\u0301|[бвгджзйклмнпрстфхцчшўьʼ]*[аеёіоуыэюя][бвгджзйклмнпрстфхцчшўьʼ]* )(?!а[бд]?|б[ея]зь?|[дз]а|д?ля|дзеля|[нп]ад?|пр[аы]|празь?|у|церазь?)/g,
10
10
  ' ня ',
11
11
  ],
12
12
  // / без(?=ь? (?:
@@ -14,7 +14,7 @@ export const endZSoftenAndNiaBiaz = callableDict([
14
14
  // |{зычны}*{галосны}{зычны}*{канец слова}
15
15
  // )/
16
16
  [
17
- / без(?=ь? (?:[бвгджзйклмнпхрстфхцчшўьʼ]*.\u0301|[бвгджзйклмнпхрстфхцчшўьʼ]*[аеёіоуыэюя][бвгджзйклмнпхрстфхцчшўьʼ]* ))/g,
17
+ / без(?=ь? (?:[бвгджзйклмнпрстфхцчшўьʼ]*.\u0301|[бвгджзйклмнпрстфхцчшўьʼ]*[аеёіоуыэюя][бвгджзйклмнпрстфхцчшўьʼ]* ))/g,
18
18
  ' бяз',
19
19
  ],
20
20
 
@@ -3,19 +3,29 @@
3
3
  *
4
4
  * If you want to create your own pipeline
5
5
  * based on a builtin one and do it safely, use
6
- * `.map` if you need replacing only or
7
- * `.flatMap` if you also need to add or remove steps.
6
+ * `pipeline.steps.map` if you need replacing only or
7
+ * `pipeline.steps.flatMap` if you also need to add or remove steps.
8
+ *
9
+ * Then pass the result to {@link createPipeline}.
8
10
  *
9
11
  * This way you will depend less on the
10
- * internal structure of the builtin pipeline.
12
+ * internal order of the builtin pipeline steps.
11
13
  *
12
- * For cases when you need to replace only {@link steps.taraskevize} in {@link tar}
14
+ * For cases when you need to replace only {@link steps.taraskevize} in {@link tarask}
13
15
  * and have better tree-shaking, you can use {@link _createPipeline}.
14
16
  *
15
17
  * @module
16
18
  */
19
+ import { TaraskConfig } from './config';
17
20
  import { type TaraskStep } from './steps';
18
- export type Pipeline = TaraskStep<any>[];
21
+ export type Pipeline = {
22
+ (text: string, cfg?: Partial<TaraskConfig>): string;
23
+ steps: TaraskStep<any>[];
24
+ };
25
+ /**
26
+ * Create a callable pipeline from steps.
27
+ */
28
+ export declare const createPipeline: (steps: TaraskStep<any>[]) => Pipeline;
19
29
  /**
20
30
  * Pipeline for changing only the alphabet.
21
31
  *
@@ -23,21 +33,21 @@ export type Pipeline = TaraskStep<any>[];
23
33
  *
24
34
  * To see the full list of steps, check the source code.
25
35
  */
26
- export declare const abc: (TaraskStep<import("./steps").SpecialSyntaxStorage> | TaraskStep<import("./steps").WhiteSpaceStorage> | TaraskStep<import("./steps").TrimStorage>)[];
36
+ export declare const alphabetic: Pipeline;
27
37
  /**
28
38
  * For better tree-shaking instead of `Array.prototype.flatMap`
29
39
  *
30
- * Used by {@link tar} and {@link phonetic}.
40
+ * Used by {@link tarask} and {@link phonetic}.
31
41
  *
32
42
  * @param subPipeline - Steps used instead of [{@link steps.taraskevize}].
33
43
  */
34
- export declare const _createPipeline: (subPipeline: Pipeline) => (TaraskStep<import("./steps").SplittedTextStorage> | TaraskStep<import("./steps").SpecialSyntaxStorage> | TaraskStep<import("./steps").WhiteSpaceStorage> | TaraskStep<import("./steps").TrimStorage>)[];
44
+ export declare const _createPipeline: (subPipeline: TaraskStep<any>[]) => Pipeline;
35
45
  /**
36
46
  * Pipeline for taraskevizing.
37
47
  */
38
- export declare const tar: (TaraskStep<import("./steps").SplittedTextStorage> | TaraskStep<import("./steps").SpecialSyntaxStorage> | TaraskStep<import("./steps").WhiteSpaceStorage> | TaraskStep<import("./steps").TrimStorage>)[];
48
+ export declare const tarask: Pipeline;
39
49
  /**
40
50
  * Pipeline for phonetizing.
41
51
  * @alpha
42
52
  */
43
- export declare const phonetic: (TaraskStep<import("./steps").SplittedTextStorage> | TaraskStep<import("./steps").SpecialSyntaxStorage> | TaraskStep<import("./steps").WhiteSpaceStorage> | TaraskStep<import("./steps").TrimStorage>)[];
53
+ export declare const phonetic: Pipeline;
package/dist/pipelines.js CHANGED
@@ -1,7 +1,23 @@
1
1
 
2
+ import { TaraskConfig } from './config.js';
2
3
  import { highlightDiffStep, applyNoFix, convertAlphabet, convertAlphabetLowerCase, joinSplittedText, prepare, replaceIbyJ, resolveSpecialSyntax, restoreCaseStep, restoreWhitespaces, storeSplittedAbcConvertedOrig, storeSplittedText, taraskevize, phonetize, whitespacesToSpaces, trim, finalize, toLowerCase, iotacizeJi, untrim, applyG, applyVariations, } from './steps/index.js';
3
4
 
4
- export const abc = [
5
+ export const createPipeline = (steps) => {
6
+ const fn = (text, cfg = new TaraskConfig()) => {
7
+ const ctx = {
8
+ text,
9
+ cfg: cfg instanceof TaraskConfig ? cfg : new TaraskConfig(cfg),
10
+ storage: {},
11
+ };
12
+ for (const step of fn.steps)
13
+ step(ctx);
14
+ return ctx.text;
15
+ };
16
+ fn.steps = steps;
17
+ return fn;
18
+ };
19
+
20
+ export const alphabetic = createPipeline([
5
21
  (ctx) => {
6
22
  ctx.cfg = { ...ctx.cfg, doEscapeCapitalized: false };
7
23
  },
@@ -14,9 +30,9 @@ export const abc = [
14
30
  applyNoFix,
15
31
  finalize,
16
32
  untrim,
17
- ];
33
+ ]);
18
34
 
19
- export const _createPipeline = (subPipeline) => [
35
+ export const _createPipeline = (subPipeline) => createPipeline([
20
36
  trim,
21
37
  resolveSpecialSyntax,
22
38
  prepare,
@@ -36,8 +52,8 @@ export const _createPipeline = (subPipeline) => [
36
52
  applyNoFix,
37
53
  finalize,
38
54
  untrim,
39
- ];
55
+ ]);
40
56
 
41
- export const tar = _createPipeline([taraskevize]);
57
+ export const tarask = _createPipeline([taraskevize]);
42
58
 
43
59
  export const phonetic = _createPipeline([phonetize, iotacizeJi]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taraskevizer",
3
- "version": "9.3.4",
3
+ "version": "10.0.0-alpha.0",
4
4
  "author": "GooseOb",
5
5
  "repository": {
6
6
  "type": "git",
package/dist/tarask.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { TaraskConfig } from './config';
2
- import type { Pipeline } from './pipelines';
3
- /**
4
- * @returns converted text
5
- *
6
- * @example
7
- * tarask("планета", pipelines.tar);
8
- * // "плянэта"
9
- */
10
- export declare const tarask: (text: string, pipeline: Pipeline, cfg?: Readonly<TaraskConfig>) => string;
package/dist/tarask.js DELETED
@@ -1,8 +0,0 @@
1
- import { TaraskConfig } from './config.js';
2
-
3
- export const tarask = (text, pipeline, cfg = new TaraskConfig()) => {
4
- const ctx = { text, cfg, storage: {} };
5
- for (const step of pipeline)
6
- step(ctx);
7
- return ctx.text;
8
- };