From 3829018f06cbe76d9a7511f8ada48bd8d3d87760 Mon Sep 17 00:00:00 2001 From: Bauke Date: Mon, 7 Mar 2022 22:32:24 +0100 Subject: [PATCH] Add an automatic way to exclude default values from graphs. --- source/gegl/base.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/gegl/base.ts b/source/gegl/base.ts index e809032..32762d6 100644 --- a/source/gegl/base.ts +++ b/source/gegl/base.ts @@ -17,10 +17,19 @@ export abstract class BaseOperation

{ this.parameters = parameters; } - public graph(): string[] { + public graph(includeDefaults = false): string[] { + const defaults = this.default; const graph: string[] = [this.name]; for (const [key, value] of Object.entries(this.parameters)) { + if ( + includeDefaults && + key in defaults && + (defaults as Record)[key] === value + ) { + continue; + } + const kebabCasedKey = key.replace(/([A-Z])/g, '-$1').toLowerCase(); graph.push(`${kebabCasedKey}=${value as string}`); }