MCPcopy Create free account
hub / github.com/dapi-labs/react-nice-avatar / pickByHashCode

Function pickByHashCode

src/utils.ts:116–135  ·  view source on GitHub ↗
(code: number, type: keyof DefaultOptions, opts?: PickByHashCodeOpts)

Source from the content-addressed store, hash-verified

114 usually?: string[]
115}
116const pickByHashCode = (code: number, type: keyof DefaultOptions, opts?: PickByHashCodeOpts): string => {
117 const avoidList = opts && opts.avoidList || []
118 const usually = opts && opts.usually || []
119
120 // Filter out avoid options
121 const avoidSet = new Set<string>(avoidList)
122 let myDefaultOptions = defaultOptions[type].filter(item => !avoidSet.has(item))
123
124 // Increase selecting possibility of usually options
125 myDefaultOptions = usually
126 .filter(Boolean)
127 .reduce(
128 (acc, cur) => acc.concat(new Array(15).fill(cur)),
129 [] as string[]
130 )
131 .concat(myDefaultOptions)
132
133 const index = code % myDefaultOptions.length
134 return myDefaultOptions[index]
135}
136
137export const genConfig: GenConfigFunc = (userConfig = {}) => {
138 const isSeedConfig = typeof userConfig === 'string';

Callers 1

genConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…