MCPcopy
hub / github.com/formatjs/formatjs / orderObjectByKeys

Function orderObjectByKeys

tools/generate-package-json.ts:154–175  ·  view source on GitHub ↗
(
  object: JsonObject,
  keysFirst: string[]
)

Source from the content-addressed store, hash-verified

152}
153
154function orderObjectByKeys(
155 object: JsonObject,
156 keysFirst: string[]
157): JsonObject {
158 const result: JsonObject = {}
159 const seen = new Set<string>()
160
161 for (const key of keysFirst) {
162 if (Object.hasOwn(object, key)) {
163 result[key] = object[key]
164 seen.add(key)
165 }
166 }
167
168 for (const key of Object.keys(object)
169 .filter(key => !seen.has(key))
170 .sort()) {
171 result[key] = object[key]
172 }
173
174 return result
175}
176
177function orderExports(value: JsonValue, sortExports: string[]): JsonValue {
178 if (!value || typeof value !== 'object' || Array.isArray(value)) {

Callers 2

orderExportsFunction · 0.85
generatePackageJsonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected