@naturalcycles/nodejs-lib 12.90.0 → 12.90.2

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.
@@ -13,9 +13,9 @@ class CSVWriter {
13
13
  }
14
14
  writeRows(rows) {
15
15
  let s = '';
16
- if (this.cfg.includeHeader) {
17
- // Detect columns based on content, if not defined upfront
18
- this.cfg.columns ||= arrayToCSVColumns(rows);
16
+ // Detect columns based on content, if not defined upfront
17
+ this.cfg.columns ||= arrayToCSVColumns(rows);
18
+ if (this.cfg.includeHeader && rows.length) {
19
19
  s += this.writeHeader() + '\n';
20
20
  }
21
21
  return s + rows.map(row => this.writeRow(row)).join('\n');
@@ -1,4 +1,4 @@
1
- import { AbortableAsyncMapper, AsyncPredicate, CommonLogger, ErrorMode } from '@naturalcycles/js-lib';
1
+ import { AbortableAsyncMapper, AsyncPredicate, CommonLogger, END, ErrorMode, SKIP } from '@naturalcycles/js-lib';
2
2
  import { TransformTyped } from '../stream.model';
3
3
  export interface TransformMapOptions<IN = any, OUT = IN> {
4
4
  /**
@@ -50,4 +50,4 @@ export interface TransformMapOptions<IN = any, OUT = IN> {
50
50
  *
51
51
  * If an Array is returned by `mapper` - it will be flattened and multiple results will be emitted from it. Tested by Array.isArray().
52
52
  */
53
- export declare function transformMap<IN = any, OUT = IN>(mapper: AbortableAsyncMapper<IN, OUT>, opt?: TransformMapOptions<IN, OUT>): TransformTyped<IN, OUT>;
53
+ export declare function transformMap<IN = any, OUT = IN>(mapper: AbortableAsyncMapper<IN, OUT | typeof SKIP | typeof END>, opt?: TransformMapOptions<IN, OUT>): TransformTyped<IN, OUT>;
@@ -1,4 +1,4 @@
1
- import { CommonLogger, ErrorMode, Mapper, Predicate } from '@naturalcycles/js-lib';
1
+ import { CommonLogger, END, ErrorMode, Mapper, Predicate, SKIP } from '@naturalcycles/js-lib';
2
2
  import { AbortableTransform } from '../pipeline/pipeline';
3
3
  import { TransformTyped } from '../stream.model';
4
4
  export interface TransformMapSyncOptions<IN = any, OUT = IN> {
@@ -42,4 +42,4 @@ export declare class TransformMapSync extends AbortableTransform {
42
42
  * Sync (not async) version of transformMap.
43
43
  * Supposedly faster, for cases when async is not needed.
44
44
  */
45
- export declare function transformMapSync<IN = any, OUT = IN>(mapper: Mapper<IN, OUT>, opt?: TransformMapSyncOptions): TransformTyped<IN, OUT>;
45
+ export declare function transformMapSync<IN = any, OUT = IN>(mapper: Mapper<IN, OUT | typeof SKIP | typeof END>, opt?: TransformMapSyncOptions): TransformTyped<IN, OUT>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.90.0",
3
+ "version": "12.90.2",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -32,10 +32,11 @@ export class CSVWriter {
32
32
 
33
33
  writeRows(rows: AnyObject[]): string {
34
34
  let s = ''
35
- if (this.cfg.includeHeader) {
36
- // Detect columns based on content, if not defined upfront
37
- this.cfg.columns ||= arrayToCSVColumns(rows)
38
35
 
36
+ // Detect columns based on content, if not defined upfront
37
+ this.cfg.columns ||= arrayToCSVColumns(rows)
38
+
39
+ if (this.cfg.includeHeader && rows.length) {
39
40
  s += this.writeHeader() + '\n'
40
41
  }
41
42
  return s + rows.map(row => this.writeRow(row)).join('\n')
@@ -75,7 +75,7 @@ export interface TransformMapOptions<IN = any, OUT = IN> {
75
75
  * If an Array is returned by `mapper` - it will be flattened and multiple results will be emitted from it. Tested by Array.isArray().
76
76
  */
77
77
  export function transformMap<IN = any, OUT = IN>(
78
- mapper: AbortableAsyncMapper<IN, OUT>,
78
+ mapper: AbortableAsyncMapper<IN, OUT | typeof SKIP | typeof END>,
79
79
  opt: TransformMapOptions<IN, OUT> = {},
80
80
  ): TransformTyped<IN, OUT> {
81
81
  const {
@@ -61,7 +61,7 @@ export class TransformMapSync extends AbortableTransform {}
61
61
  * Supposedly faster, for cases when async is not needed.
62
62
  */
63
63
  export function transformMapSync<IN = any, OUT = IN>(
64
- mapper: Mapper<IN, OUT>,
64
+ mapper: Mapper<IN, OUT | typeof SKIP | typeof END>,
65
65
  opt: TransformMapSyncOptions = {},
66
66
  ): TransformTyped<IN, OUT> {
67
67
  let index = -1