MCPcopy
hub / github.com/fingerprintjs/fingerprintjs / transformSource

Function transformSource

src/utils/entropy_source.ts:167–196  ·  view source on GitHub ↗
(
  source: Source<TOptions, TValueBefore>,
  transformValue: (value: TValueBefore) => TValueAfter,
)

Source from the content-addressed store, hash-verified

165 * This function is out of Semantic Versioning, i.e. can change unexpectedly. Usage is at your own risk.
166 */
167export function transformSource<TOptions, TValueBefore, TValueAfter>(
168 source: Source<TOptions, TValueBefore>,
169 transformValue: (value: TValueBefore) => TValueAfter,
170): Source<TOptions, TValueAfter> {
171 const transformLoadResult = (loadResult: TValueBefore | (() => MaybePromise<TValueBefore>)) => {
172 if (isFinalResultLoaded(loadResult)) {
173 return transformValue(loadResult)
174 }
175
176 return () => {
177 const getResult = loadResult()
178
179 if (isPromise(getResult)) {
180 return getResult.then(transformValue)
181 }
182
183 return transformValue(getResult)
184 }
185 }
186
187 return (options) => {
188 const loadResult = source(options)
189
190 if (isPromise(loadResult)) {
191 return loadResult.then(transformLoadResult)
192 }
193
194 return transformLoadResult(loadResult)
195 }
196}

Callers 2

checkSourceFunction · 0.90

Calls 3

isPromiseFunction · 0.90
sourceFunction · 0.85
transformLoadResultFunction · 0.85

Tested by 1

checkSourceFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…