Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 17 additions & 17 deletions src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any> = {};
logger: { log: (value: any) => void } = { log() {} };

Expand All @@ -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}`);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();