From 9f21b81d9a510b4f329ddbcf4e4f2fe080889e73 Mon Sep 17 00:00:00 2001 From: henryhai Date: Mon, 25 Mar 2024 10:33:23 +0700 Subject: [PATCH] show log only when showDebug is true --- .github/workflows/ci.yml | 4 ++-- readme.md | 14 +++++++------- src/index.ts | 9 +++++++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c49ddc2..0eedcd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,9 +9,9 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - name: Use Node.js 8.x - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: registry-url: https://npm.pkg.github.com/ node-version: 8.x diff --git a/readme.md b/readme.md index 3b463a0..46ad3b0 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,7 @@ Typescript package for parsing grpc chunk data First, add a `.npmrc` file with the following content: -``` +```npmrc @alphauslabs:registry=https://npm.pkg.github.com ``` @@ -17,7 +17,7 @@ Then install: Import the **parseGrpcData** function in your file via the command -``` +```ts import { parseGrpcData } from '@alphauslabs/grpc-chunk-parser'; ``` @@ -42,7 +42,7 @@ parseGrpcData has **5 parameters**: ## Example -``` +```ts import { parseGrpcData } from '@alphauslabs/grpc-chunk-parser'; parseGrpcData( @@ -57,8 +57,8 @@ parseGrpcData( } }, { - limiter: 20, // Every 20 items received, the function in - // param 3 `onChunkReceive` will be called. + showDebug: true, // default false (optional) + limiter: 20, // Every 20 items received, the function in param 3 `onChunkReceive` will be called. concatData: false, objectPrefix: 'result.aws', }, @@ -66,10 +66,10 @@ parseGrpcData( console.log('returned data', data); }, (fullData: any) => { - console.log('On finish here', fullData) + console.log('On finish here', fullData); }, (err: any) => { - console.log('Error here, err) + console.log('Error here, err'); } ); ``` diff --git a/src/index.ts b/src/index.ts index 2b80ac9..b6c8ba0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,15 +20,20 @@ export const parseGrpcData = async ( onError?: (e: any) => void ) => { try { - console.time('parseGrpcData'); + const { url, method, headers } = requestObject; const { limiter = 1, concatData = false, showDebug = false } = dataObject ?? {}; + let objectPrefix = dataObject?.objectPrefix ?? 'result'; const allData: DynamicObject[] = []; const limiterData: DynamicObject[] = []; const hasLimiter = limiter && limiter > 0; + if (showDebug) { + console.time('parseGrpcData'); + } + const res: any = await fetch(url, { method: method.toUpperCase(), headers, @@ -144,8 +149,8 @@ export const parseGrpcData = async ( if (showDebug) { console.log("count: ", count); console.log("failed count: ", failedCount); + console.timeEnd('parseGrpcData'); } - console.timeEnd('parseGrpcData'); onFinish(allData); } } catch (error) {