From eb78b8fa6baaefcb1ca188f91e5724a50dbbca9b Mon Sep 17 00:00:00 2001 From: Oleksandr_Halichenko Date: Tue, 14 Oct 2025 14:33:26 +0300 Subject: [PATCH 1/2] moved `toString` util to memory instance as `convertToString` method to enable alteration of stringify logic --- CHANGELOG.MD | 14 ++++++++++++++ package.json | 2 +- src/memory.ts | 34 +++++++++++++++++----------------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index e128e09..cc3e886 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -4,6 +4,20 @@ All notable changes to the "@qavajs/memory" will be documented in this file. Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +:rocket: - new feature +:beetle: - bugfix +:x: - deprecation/removal +:pencil: - chore +:microscope: - experimental + +## [Unreleased] +- :rocket: moved `toString` util to memory instance as `convertToString` method to enable alteration of stringify logic +```typescript +memory.convertToString = function(value: string) { + return util.inspect(value); +} +``` + ## [1.10.3] - :beetle: fixed `parallel` util function to allow undefined values diff --git a/package.json b/package.json index 8364848..80c5c06 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ ], "license": "MIT", "devDependencies": { - "@types/node": "^24.7.1", + "@types/node": "^24.7.2", "@vitest/coverage-v8": "^3.2.4", "@vitest/ui": "^3.2.4", "typescript": "^5.9.3", diff --git a/src/memory.ts b/src/memory.ts index da465c7..9d8f54a 100644 --- a/src/memory.ts +++ b/src/memory.ts @@ -15,23 +15,8 @@ class MemoryError extends Error { super(error); } } -function toString(value: any): string { - let logValue = value; - try { - if (typeof value === 'object') { - logValue = JSON.stringify(value, null, 2); - } - } catch (err) { - logValue = value.toString(); - } - if (typeof logValue === 'string') { - return logValue.slice(0, TRUNCATE_LOG); - } - return logValue; -} class Memory { - storage: Record = {}; logger: { log: (value: any) => void } = { log() {} }; @@ -49,7 +34,7 @@ class Memory { if (KEY_REGEXP.test(value)) value = this.getKey(value); else if (PARSE_STRING_REGEXP.test(value)) value = this.getString(value); if (typeof value === 'string') value = value.replace(UNESCAPE_DOLLAR_REGEXP, '$'); - const stringValue = toString(value); + const stringValue = this.convertToString(value); if (stringValue !== str) { this.logger.log(`${str} -> ${stringValue}`); } @@ -83,7 +68,7 @@ class Memory { */ @readonly setValue(key: string, value: any) { - this.logger.log(`$${key} <- ${toString(value)}`); + this.logger.log(`$${key} <- ${this.convertToString(value)}`); this.storage[key] = value; } @@ -123,6 +108,21 @@ class Memory { this.logger = logger; } + convertToString(value: any): string { + let logValue = value; + try { + if (typeof value === 'object') { + logValue = JSON.stringify(value, null, 2); + } + } catch (err) { + logValue = value.toString(); + } + if (typeof logValue === 'string') { + return logValue.slice(0, TRUNCATE_LOG); + } + return logValue; + } + } export default new Memory(); \ No newline at end of file From 7acb32ced20b2d688fe129ce0b075efbaaa8c2f3 Mon Sep 17 00:00:00 2001 From: Oleksandr_Halichenko Date: Tue, 14 Oct 2025 14:34:48 +0300 Subject: [PATCH 2/2] update package-lock.json --- package-lock.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 497bbb0..6f02274 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.10.3", "license": "MIT", "devDependencies": { - "@types/node": "^24.7.1", + "@types/node": "^24.7.2", "@vitest/coverage-v8": "^3.2.4", "@vitest/ui": "^3.2.4", "typescript": "^5.9.3", @@ -964,9 +964,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.7.1.tgz", - "integrity": "sha512-CmyhGZanP88uuC5GpWU9q+fI61j2SkhO3UGMUdfYRE6Bcy0ccyzn1Rqj9YAB/ZY4kOXmNf0ocah5GtphmLMP6Q==", + "version": "24.7.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.7.2.tgz", + "integrity": "sha512-/NbVmcGTP+lj5oa4yiYxxeBjRivKQ5Ns1eSZeB99ExsEQ6rX5XYU1Zy/gGxY/ilqtD4Etx9mKyrPxZRetiahhA==", "dev": true, "license": "MIT", "dependencies": { @@ -2957,9 +2957,9 @@ "dev": true }, "@types/node": { - "version": "24.7.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.7.1.tgz", - "integrity": "sha512-CmyhGZanP88uuC5GpWU9q+fI61j2SkhO3UGMUdfYRE6Bcy0ccyzn1Rqj9YAB/ZY4kOXmNf0ocah5GtphmLMP6Q==", + "version": "24.7.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.7.2.tgz", + "integrity": "sha512-/NbVmcGTP+lj5oa4yiYxxeBjRivKQ5Ns1eSZeB99ExsEQ6rX5XYU1Zy/gGxY/ilqtD4Etx9mKyrPxZRetiahhA==", "dev": true, "requires": { "undici-types": "~7.14.0"