MCPcopy Create free account
hub / github.com/AlexErrant/Pentive / unflattenObject

Function unflattenObject

app/src/sqlite/settings.ts:173–195  ·  view source on GitHub ↗
(
	flattened: Array<readonly [string, SettingEntity['value']]>,
)

Source from the content-addressed store, hash-verified

171}
172
173export function unflattenObject(
174 flattened: Array<readonly [string, SettingEntity['value']]>,
175) {
176 const result = Object.create(null) as SettingRecord
177 for (const [key, value] of flattened) {
178 const keys = key.split(delimiter)
179 let currentLevel: SettingRecord = result
180 for (let i = 0; i < keys.length; i++) {
181 const segment = keys[i]!
182 if (/* "is last" */ i === keys.length - 1) {
183 if (ArrayBuffer.isView(value)) {
184 currentLevel[segment] = decodeValue(value)
185 } else {
186 currentLevel[segment] = value
187 }
188 } else {
189 currentLevel = (currentLevel[segment] as SettingRecord | undefined) ??=
190 Object.create(null) as SettingRecord
191 }
192 }
193 }
194 return result
195}
196
197// The point of this type is to cause an error if something is added to SettingEntity
198// If that happens, you probably want to update the `doUpdateSet` call.

Callers 1

getSettingsFunction · 0.85

Calls 1

decodeValueFunction · 0.85

Tested by

no test coverage detected