mirror of
https://github.com/jwinterm/rarity-analyser.git
synced 2026-10-17 05:41:40 +02:00
Add config option to ignore trait types
This commit is contained in:
@@ -43,11 +43,22 @@ Add weights to scale rarity scores up or down.
|
||||
{
|
||||
weights: {
|
||||
"Trait A": 1.2,
|
||||
"Trait B": 0,
|
||||
"Trait B": 0.1,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ignoreTraits
|
||||
Array of trait types to be ignored by the rarity analyser.
|
||||
|
||||
```typescript
|
||||
{
|
||||
ingoreTraits: [
|
||||
'Trait x',
|
||||
'Trait y',
|
||||
]
|
||||
}
|
||||
```
|
||||
### getMissingTraitIdentifier
|
||||
`(trait_type?: string) => string | undefined`
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ const config: Config = {
|
||||
// weights: {},
|
||||
// getMissingTraitIdentifier: (trait_type?: string) => undefined,
|
||||
// attributesFieldName: 'attributes',
|
||||
// ignoreTraits: []
|
||||
}
|
||||
|
||||
export default config
|
||||
|
||||
+12
-1
@@ -106,6 +106,12 @@ export const analyse = (
|
||||
}
|
||||
}
|
||||
|
||||
const filterIgnored = (tokens: Token[], ignoredTraits: string[]) => tokens.map(token => ({
|
||||
...token,
|
||||
attributes: token.attributes.filter(attribute => (
|
||||
!(ignoredTraits.includes(attribute.trait_type))
|
||||
))
|
||||
}))
|
||||
|
||||
const preprocess = (
|
||||
tokens: Record<string, string | number | Attribute[]>[]
|
||||
@@ -152,7 +158,12 @@ const preprocess = (
|
||||
t = mapped
|
||||
}
|
||||
|
||||
return t as Token[]
|
||||
let result: Token[]
|
||||
if (config.ignoreTraits !== undefined)
|
||||
result = filterIgnored(t as Token[], config.ignoreTraits)
|
||||
else result = t as Token[]
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,6 +72,7 @@ export interface Config {
|
||||
weights?: Weights
|
||||
getMissingTraitIdentifier?: GetMissingTraitIdentifier
|
||||
attributesFieldName?: string
|
||||
ignoreTraits?: string[]
|
||||
}
|
||||
|
||||
export type AttributeWithRarity = Attribute & RarityFields
|
||||
|
||||
Reference in New Issue
Block a user