@livefolio/sdk / paramsHash
Function: paramsHash()
paramsHash(
spec):string
Defined in: features/spec.ts:162
Returns a deterministic string that depends only on the spec's logical content — key order and undefined optional fields are normalized away.
The same logical spec always produces the same hash regardless of how the object was constructed (different key insertion order, explicit undefined vs. omitted optional field). This string is used as the paramsHash field in FeatureKey to ensure cache-hit equivalence for semantically identical specs.
Callers depend on this function's contract (same logical content → same result), not on the encoding. Future replacement with SHA-256 is non-breaking.
Parameters
| Parameter | Type | Description |
|---|---|---|
spec | FeatureSpec | The FeatureSpec object to hash. |
Returns
string
A JSON string with sorted keys and no undefined values.
Example
ts
import { paramsHash } from '@livefolio/sdk';
paramsHash({ kind: 'sma', period: 20 });
// => '{"kind":"sma","period":20}'
// Optional field omitted vs explicitly undefined — same result:
paramsHash({ kind: 'return', period: 10 });
paramsHash({ kind: 'return', period: 10, mode: undefined });
// both => '{"kind":"return","period":10}'