@ezs/basics 1.24.0 → 2.0.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/CHANGELOG.md +17 -0
- package/README.md +7 -3
- package/lib/txt-sentences.js +16 -26
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.0.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.24.0...@ezs/basics@2.0.0) (2023-03-29)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **basics:** Make TXTSentences pass some tests ([95bd41f](https://github.com/Inist-CNRS/ezs/commit/95bd41f836e5ee2f71c8413142df9ac4dd9ec84b))
|
|
12
|
+
* **basics:** Make TXTSentences work with arrays too ([24c3f76](https://github.com/Inist-CNRS/ezs/commit/24c3f76be73a518791e59b7e78c4d1151af8edd6))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### BREAKING CHANGES
|
|
16
|
+
|
|
17
|
+
* **basics:** TXTSentences xxpected structure is now an object, with a value key.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
6
23
|
# [1.24.0](https://github.com/Inist-CNRS/ezs/compare/@ezs/basics@1.23.5...@ezs/basics@1.24.0) (2023-03-28)
|
|
7
24
|
|
|
8
25
|
|
package/README.md
CHANGED
|
@@ -609,16 +609,20 @@ Take a `String` and split it into an array of sentences.
|
|
|
609
609
|
Input:
|
|
610
610
|
|
|
611
611
|
```json
|
|
612
|
-
"First sentence? Second sentence. My name is Bond, J. Bond."
|
|
612
|
+
{ "id": 1, "value": "First sentence? Second sentence. My name is Bond, J. Bond." }
|
|
613
613
|
```
|
|
614
614
|
|
|
615
615
|
Output:
|
|
616
616
|
|
|
617
617
|
```json
|
|
618
|
-
["First sentence?", "Second sentence.", "My name is Bond, J. Bond."]
|
|
618
|
+
{ "id": 1, "value": ["First sentence?", "Second sentence.", "My name is Bond, J. Bond."] }
|
|
619
619
|
```
|
|
620
620
|
|
|
621
|
-
|
|
621
|
+
#### Parameters
|
|
622
|
+
|
|
623
|
+
- `path` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path of the field to segment (optional, default `"value"`)
|
|
624
|
+
|
|
625
|
+
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
|
|
622
626
|
|
|
623
627
|
### TXTZip
|
|
624
628
|
|
package/lib/txt-sentences.js
CHANGED
|
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash.get"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
11
|
|
|
10
12
|
const UPPER_LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
11
13
|
const SENTENCE_INIT = ' ';
|
|
@@ -17,7 +19,7 @@ const SENTENCE_ENDING = '.?!';
|
|
|
17
19
|
*/
|
|
18
20
|
|
|
19
21
|
const segmentSentences = str => {
|
|
20
|
-
const characters =
|
|
22
|
+
const characters = Array.from(str);
|
|
21
23
|
const sentences = characters.reduce(
|
|
22
24
|
/*
|
|
23
25
|
* @param {string[]} prevSentences
|
|
@@ -43,34 +45,21 @@ const segmentSentences = str => {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
return [...prevSentences.slice(0, -1), currentSentence + character];
|
|
46
|
-
}, [SENTENCE_INIT]).map(sentence => sentence.trimStart());
|
|
48
|
+
}, [SENTENCE_INIT]).filter(sentence => sentence !== SENTENCE_INIT).map(sentence => sentence.trimStart());
|
|
47
49
|
return sentences;
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
const TXTSentences = (data, feed, ctx) => {
|
|
51
|
-
if (!ctx.decoder) {
|
|
52
|
-
ctx.decoder = new _string_decoder.StringDecoder('utf8');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
53
|
if (ctx.isLast()) {
|
|
56
|
-
|
|
57
|
-
return feed.end();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
ctx.remainder = ctx.remainder ?? '';
|
|
61
|
-
let str;
|
|
62
|
-
|
|
63
|
-
if (Buffer.isBuffer(data)) {
|
|
64
|
-
str = ctx.decoder.write(data);
|
|
65
|
-
} else if (typeof data === 'string') {
|
|
66
|
-
str = data;
|
|
54
|
+
return feed.close();
|
|
67
55
|
}
|
|
68
56
|
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
57
|
+
const path = ctx.getParam('path', 'value');
|
|
58
|
+
const value = (0, _lodash.default)(data, path);
|
|
59
|
+
const str = Array.isArray(value) ? value.map(item => typeof item === 'string' ? item : '').join(' ') : value;
|
|
60
|
+
const sentences = str ? segmentSentences(str) : [];
|
|
61
|
+
feed.write({ ...data,
|
|
62
|
+
[path]: sentences
|
|
74
63
|
});
|
|
75
64
|
return feed.end();
|
|
76
65
|
};
|
|
@@ -80,17 +69,18 @@ const TXTSentences = (data, feed, ctx) => {
|
|
|
80
69
|
* Input:
|
|
81
70
|
*
|
|
82
71
|
* ```json
|
|
83
|
-
* "First sentence? Second sentence. My name is Bond, J. Bond."
|
|
72
|
+
* { "id": 1, "value": "First sentence? Second sentence. My name is Bond, J. Bond." }
|
|
84
73
|
* ```
|
|
85
74
|
*
|
|
86
75
|
* Output:
|
|
87
76
|
*
|
|
88
77
|
* ```json
|
|
89
|
-
* ["First sentence?", "Second sentence.", "My name is Bond, J. Bond."]
|
|
78
|
+
* { "id": 1, "value": ["First sentence?", "Second sentence.", "My name is Bond, J. Bond."] }
|
|
90
79
|
* ```
|
|
91
80
|
*
|
|
92
81
|
* @name TXTSentences
|
|
93
|
-
* @
|
|
82
|
+
* @param {String} [path="value"] path of the field to segment
|
|
83
|
+
* @returns {String[]}
|
|
94
84
|
*/
|
|
95
85
|
|
|
96
86
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ezs/basics",
|
|
3
3
|
"description": "Basics statements for EZS",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>",
|
|
6
6
|
"bugs": "https://github.com/Inist-CNRS/ezs/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"directories": {
|
|
40
40
|
"test": "test"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "314a26ebcbf109ffdb6936ee4b8564e19dd17cbc",
|
|
43
43
|
"homepage": "https://github.com/Inist-CNRS/ezs/tree/master/packages/basics#readme",
|
|
44
44
|
"keywords": [
|
|
45
45
|
"ezs"
|