Skip to content

Commit

Permalink
refactor: remove node:inspect for a custom method
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Nov 28, 2023
1 parent fb0fa1e commit 6466457
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/scripts/object/move_unknown_properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* file that was distributed with this source code.
*/

import { inspect } from 'node:util'

/**
* Options accepts by the output script
*/
Expand All @@ -18,6 +16,14 @@ type MovePropertiesOptions = {
fieldsToIgnore: string[]
}

/**
* Converts an array of strings to a string representation
* like ["foo", "bar"]. Just like node:inspect does.
*/
function arrayToString(arr: string[]) {
return `[${arr.map((str) => `"${str}"`).join(', ')}]`
}

/**
* Returns JS fragment for moving properties from the source
* to destination
Expand All @@ -30,5 +36,7 @@ export function defineMoveProperties({
if (!allowUnknownProperties) {
return ''
}
return `moveProperties(${variableName}.value, ${variableName}_out, ${inspect(fieldsToIgnore)});`

const serializedFieldsToIgnore = arrayToString(fieldsToIgnore)
return `moveProperties(${variableName}.value, ${variableName}_out, ${serializedFieldsToIgnore});`
}

0 comments on commit 6466457

Please sign in to comment.