MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / normalizeDecimalDefault

Function normalizeDecimalDefault

packages/cli/src/actions/pull/utils.ts:218–231  ·  view source on GitHub ↗
(val: string)

Source from the content-addressed store, hash-verified

216 * - Decimal strings are normalized to minimum 2 decimal places, stripping excess trailing zeros
217 */
218export function normalizeDecimalDefault(val: string): (ab: ExpressionBuilder) => AstFactory<Expression> {
219 if (/^-?\d+$/.test(val)) {
220 return (ab) => ab.NumberLiteral.setValue(val + '.00');
221 }
222 if (/^-?\d+\.\d+$/.test(val)) {
223 const [integerPart, fractionalPart] = val.split('.');
224 let normalized = fractionalPart!.replace(/0+$/, '');
225 if (normalized.length < 2) {
226 normalized = normalized.padEnd(2, '0');
227 }
228 return (ab) => ab.NumberLiteral.setValue(`${integerPart}.${normalized}`);
229 }
230 return (ab) => ab.NumberLiteral.setValue(val);
231}

Callers 3

getDefaultValueFunction · 0.90
getDefaultValueFunction · 0.90
getDefaultValueFunction · 0.90

Calls 1

setValueMethod · 0.45

Tested by

no test coverage detected