Add config option to ignore trait types

This commit is contained in:
Mikko
2021-09-28 12:35:41 +03:00
parent 780f6d5c13
commit c78ee9d5b5
4 changed files with 26 additions and 2 deletions
+12 -1
View File
@@ -43,11 +43,22 @@ Add weights to scale rarity scores up or down.
{ {
weights: { weights: {
"Trait A": 1.2, "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 ### getMissingTraitIdentifier
`(trait_type?: string) => string | undefined` `(trait_type?: string) => string | undefined`
+1
View File
@@ -4,6 +4,7 @@ const config: Config = {
// weights: {}, // weights: {},
// getMissingTraitIdentifier: (trait_type?: string) => undefined, // getMissingTraitIdentifier: (trait_type?: string) => undefined,
// attributesFieldName: 'attributes', // attributesFieldName: 'attributes',
// ignoreTraits: []
} }
export default config export default config
+12 -1
View File
@@ -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 = ( const preprocess = (
tokens: Record<string, string | number | Attribute[]>[] tokens: Record<string, string | number | Attribute[]>[]
@@ -152,7 +158,12 @@ const preprocess = (
t = mapped 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
} }
/** /**
+1
View File
@@ -72,6 +72,7 @@ export interface Config {
weights?: Weights weights?: Weights
getMissingTraitIdentifier?: GetMissingTraitIdentifier getMissingTraitIdentifier?: GetMissingTraitIdentifier
attributesFieldName?: string attributesFieldName?: string
ignoreTraits?: string[]
} }
export type AttributeWithRarity = Attribute & RarityFields export type AttributeWithRarity = Attribute & RarityFields