Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@poprank/rankings

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@poprank/rankings - npm Package Compare versions

Comparing version 1.1.9 to 1.1.10

6

lib/rarity/rarity.js

@@ -103,5 +103,5 @@ "use strict";

// Call this collection's meta trait function, if it exists
var collectionMetaFunctionPair = rarity_meta_1.collectionNameMetaFunctionPairs.find(function (collectionFunctionPair) { return Object.keys(collectionFunctionPair)[0] === collection; });
if (collectionMetaFunctionPair)
metaTraits.push.apply(metaTraits, collectionMetaFunctionPair[collection](nftTraits));
var customMetaFunction = rarity_meta_1.customMetaFunctions[collection];
if (customMetaFunction)
metaTraits.push.apply(metaTraits, customMetaFunction(nftTraits));
// Calculate our "Matches" meta trait

@@ -108,0 +108,0 @@ var traitValueMatches = (0, rarity_meta_1.getNftTraitsMatches)(nftTraits, collection);

@@ -5,3 +5,3 @@ import { TraitBase } from '../types';

export declare const NONE_TRAIT = "None";
export declare const ensCollectionSlugs: readonly ["ens", "999club"];
export declare const ensCollectionSlugs: readonly ["ens", "999club", "100kclub"];
export declare type EnsCollectionSlug = typeof ensCollectionSlugs[number];

@@ -14,7 +14,7 @@ export declare const ensCollectionSizes: Record<EnsCollectionSlug, number>;

/**
* All the manual functions we use to add special "meta" traits to collections.
* All the manual functions we use to add custom "meta" traits to collections.
* These meta traits don't affect rarity at all; they just make for more meaningful
* trait filters on the frontend.
*/
export declare const collectionNameMetaFunctionPairs: Record<string, (nftTraits: TraitBase[]) => TraitBase[]>[];
export declare const customMetaFunctions: Record<string, (nftTraits: TraitBase[]) => TraitBase[]>;
/**

@@ -21,0 +21,0 @@ * Get the "match" traits for a collection. Has some collection-specific logic to add desired

@@ -17,3 +17,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getNftTraitsMatches = exports.collectionNameMetaFunctionPairs = exports.stringToKeccak256DecimalId = exports.DAYS_IN_MONTH = exports.ensCollectionSizes = exports.ensCollectionSlugs = exports.NONE_TRAIT = exports.ID_TRAIT_TYPE = exports.TRAIT_COUNT = void 0;
exports.getNftTraitsMatches = exports.customMetaFunctions = exports.stringToKeccak256DecimalId = exports.DAYS_IN_MONTH = exports.ensCollectionSizes = exports.ensCollectionSlugs = exports.NONE_TRAIT = exports.ID_TRAIT_TYPE = exports.TRAIT_COUNT = void 0;
var keccak256_1 = __importDefault(require("keccak256"));

@@ -23,6 +23,7 @@ exports.TRAIT_COUNT = 'Trait Count';

exports.NONE_TRAIT = 'None';
exports.ensCollectionSlugs = ['ens', '999club'];
exports.ensCollectionSlugs = ['ens', '999club', '100kclub'];
exports.ensCollectionSizes = {
'999club': 1000,
'ens': 10000,
'999club': 1000,
'100kclub': 100000
};

@@ -43,3 +44,3 @@ exports.DAYS_IN_MONTH = {

};
function hexToDec(s) {
var hexToDec = function (s) {
var i, j, carry;

@@ -60,3 +61,3 @@ var digits = [0];

return digits.reverse().join('');
}
};
var stringToKeccak256DecimalId = function (s, digits) {

@@ -66,28 +67,27 @@ return hexToDec((0, keccak256_1.default)("0000".concat(s).slice(-digits)).toString('hex'));

exports.stringToKeccak256DecimalId = stringToKeccak256DecimalId;
var isEven = function (x) { return x % 2 === 0; };
var ensMetaFunc = function (nftTraits, collection) {
// Early exit
var trait = nftTraits.find(function (t) { return t.displayType === 'number' && t.typeValue === exports.ID_TRAIT_TYPE; });
if (!trait)
throw new Error("This trait needs a trait with a displayType of 'number' and a typeValue of ".concat(exports.ID_TRAIT_TYPE));
// Needed vars
var max = exports.ensCollectionSizes[collection];
var digits = max.toString().length - 1;
var id = +trait.value;
var stringifiedId = "000".concat(id).slice(-digits);
var isEvenDigits = isEven(digits);
var outTraits = [];
var trait = nftTraits.find(function (t) { return t.displayType === 'number' && t.typeValue === exports.ID_TRAIT_TYPE; });
if (!trait)
throw new Error("This trait needs a trait with a displayType of 'number' and a typeValue of ".concat(exports.ID_TRAIT_TYPE));
var i = +trait.value;
var stringified = "000".concat(i).slice(-digits);
// Palindrome trait
// Palindrome (ABA, ABBA, ABABA, AABAA) trait
var isPalindrome = true;
if (digits === 4) {
var a = 0;
var b = stringified.length - 1;
while (a < b) {
if (stringified[a] !== stringified[b]) {
isPalindrome = false;
break;
}
a++;
b--;
var a = 0;
var b = stringifiedId.length - 1;
while (a < b) {
if (stringifiedId[a] !== stringifiedId[b]) {
isPalindrome = false;
break;
}
a++;
b--;
}
else if (digits === 3) {
isPalindrome = stringified[0] === stringified[2];
}
if (isPalindrome) {

@@ -102,6 +102,6 @@ outTraits.push({

// Prime trait
var isPrime = (['0', '2', '4', '5', '6', '8'].includes(stringified[digits - 1]) && i !== 2 && i !== 5) ? false : true;
var isPrime = !(['0', '2', '4', '5', '6', '8'].includes(stringifiedId[digits - 1]) && id !== 2 && id !== 5);
var c = 2;
while (c < Math.ceil(Math.sqrt(i)) && isPrime) {
if (i % c === 0) {
while (c < Math.ceil(Math.sqrt(id)) && isPrime) {
if (id % c === 0) {
isPrime = false;

@@ -120,3 +120,3 @@ }

// Fibonacci trait
var isFibonacci = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765].includes(i);
var isFibonacci = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025].includes(id);
if (isFibonacci) {

@@ -130,7 +130,15 @@ outTraits.push({

}
// ABAB trait
var isABAB = stringified.slice(0, 2) === stringified.slice(2);
if (isABAB) {
// Alternating trait
var isAlternating = false;
if (isEvenDigits) {
// Even - Check for ABAB
isAlternating = stringifiedId.slice(0, 2) === stringifiedId.slice(2);
}
else {
// Odd - Check for ABA or ABABA
isAlternating = isPalindrome && stringifiedId[0] !== stringifiedId[1];
}
if (isAlternating) {
outTraits.push({
value: 'ABAB Repeat',
value: 'Alternating',
category: 'Meta',

@@ -143,6 +151,6 @@ typeValue: 'Special',

var isDouble = false;
stringified.split('').forEach(function (char, index) {
stringifiedId.split('').forEach(function (char, index) {
if (!index)
return;
if (stringified[index - 1] === char)
if (stringifiedId[index - 1] === char)
isDouble = true;

@@ -158,40 +166,49 @@ });

}
// Double (0331, 0013, 3122, etc) trait
var isDoublePair = stringified[0] === stringified[1] && stringified[2] === stringified[3];
if (isDoublePair) {
outTraits.push({
value: 'Double Pair',
category: 'Meta',
typeValue: 'Special',
displayType: null,
});
// Double (3311, 03311, etc) Pair trait
if (digits !== 3) {
var isDoublePair = stringifiedId[0] === stringifiedId[1] && stringifiedId[2] === stringifiedId[3];
if (digits === 5) {
isDoublePair = stringifiedId[1] === stringifiedId[2] && stringifiedId[3] === stringifiedId[4];
}
if (isDoublePair) {
outTraits.push({
value: 'Double Pair',
category: 'Meta',
typeValue: 'Special',
displayType: null,
});
}
}
// Birthday trait
var day = +stringified.slice(0, 2);
var month = +stringified.slice(2, 4);
var isBirthday = month >= 1 && month <= 12 && day >= 1 && day <= exports.DAYS_IN_MONTH[month];
if (isBirthday) {
outTraits.push({
value: 'Birthday',
category: 'Meta',
typeValue: 'Special',
displayType: null,
});
if (digits === 4) {
var day = +stringifiedId.slice(0, 2);
var month = +stringifiedId.slice(2, 4);
var isBirthday = month >= 1 && month <= 12 && day >= 1 && day <= exports.DAYS_IN_MONTH[month];
if (isBirthday) {
outTraits.push({
value: 'Birthday',
category: 'Meta',
typeValue: 'Special',
displayType: null,
});
}
}
// Birthday (US) trait
var usMonth = +stringified.slice(0, 2);
var usDay = +stringified.slice(2, 4);
var isUSBirthday = usMonth >= 1 && usMonth <= 12 && usDay >= 1 && usDay <= exports.DAYS_IN_MONTH[usMonth];
if (isUSBirthday) {
outTraits.push({
value: 'Birthday (US)',
category: 'Meta',
typeValue: 'Special',
displayType: null,
});
if (digits === 4) {
var usMonth = +stringifiedId.slice(0, 2);
var usDay = +stringifiedId.slice(2, 4);
var isUSBirthday = usMonth >= 1 && usMonth <= 12 && usDay >= 1 && usDay <= exports.DAYS_IN_MONTH[usMonth];
if (isUSBirthday) {
outTraits.push({
value: 'Birthday (US)',
category: 'Meta',
typeValue: 'Special',
displayType: null,
});
}
}
// Triple Digits
// Triple (333, 3331, 33311, etc) trait
var isTriple = false;
for (var j = 0; j <= stringified.length - 3; j++) {
if (['000', '111', '222', '333', '444', '555', '666', '777', '888', '999'].includes(stringified.slice(j, j + 3)))
for (var i = 0; i <= stringifiedId.length - 3; i++) {
if (['000', '111', '222', '333', '444', '555', '666', '777', '888', '999'].includes(stringifiedId.slice(i, i + 3)))
isTriple = true;

@@ -207,15 +224,32 @@ }

}
// Triple Digits
var isQuadruple = false;
for (var j = 0; j <= stringified.length - 4; j++) {
if (['0000', '1111', '2222', '3333', '4444', '5555', '6666', '7777', '8888', '9999'].includes(stringified.slice(j, j + 4)))
isQuadruple = true;
// Quadruple (3333, 33331, etc) trait
if (digits !== 3) {
var isQuadruple = false;
for (var i = 0; i <= stringifiedId.length - 4; i++) {
if (['0000', '1111', '2222', '3333', '4444', '5555', '6666', '7777', '8888', '9999'].includes(stringifiedId.slice(i, i + 4)))
isQuadruple = true;
}
if (isQuadruple) {
outTraits.push({
value: 'Quadruple',
category: 'Meta',
typeValue: 'Special',
displayType: null,
});
}
}
if (isQuadruple) {
outTraits.push({
value: 'Quadruple',
category: 'Meta',
typeValue: 'Special',
displayType: null,
});
// Quintuple Digits
if (digits === 5) {
var isQuintuple = false;
if (['00000', '11111', '22222', '33333', '44444', '55555', '66666', '77777', '88888', '99999'].includes(stringifiedId)) {
isQuintuple = true;
}
if (isQuintuple) {
outTraits.push({
value: 'Quintuple',
category: 'Meta',
typeValue: 'Special',
displayType: null,
});
}
}

@@ -225,69 +259,64 @@ return outTraits;

/**
* All the manual functions we use to add special "meta" traits to collections.
* All the manual functions we use to add custom "meta" traits to collections.
* These meta traits don't affect rarity at all; they just make for more meaningful
* trait filters on the frontend.
*/
exports.collectionNameMetaFunctionPairs = [{
'creatureworld': function (nftTraits) {
var outTraits = [];
var bg = nftTraits.find(function (t) { return t.typeValue === 'Background'; });
var creature = nftTraits.find(function (t) { return t.typeValue === 'Creature'; });
if (bg && creature) {
if (bg.value === creature.value) {
// Add trait count
outTraits.push({
typeValue: 'Creature Background Match',
value: 'true',
category: 'Meta',
displayType: null,
});
}
exports.customMetaFunctions = {
'creatureworld': function (nftTraits) {
var outTraits = [];
var bg = nftTraits.find(function (t) { return t.typeValue === 'Background'; });
var creature = nftTraits.find(function (t) { return t.typeValue === 'Creature'; });
if (bg && creature) {
if (bg.value === creature.value) {
outTraits.push({
typeValue: 'Creature Background Match',
value: 'true',
category: 'Meta',
displayType: null,
});
}
return outTraits;
},
}, {
'deathbats-club': function (nftTraits) {
var outTraits = [];
nftTraits.forEach(function (trait) {
var tType = trait.typeValue;
if (['Brooks Wackerman', 'Johnny Christ', 'M. Shadows', 'Synyster Gates', 'Zacky Vengence', 'Zacky Vengeance', 'Shadows'].includes(tType) && !Object.keys(outTraits).includes('1 of 1')) {
outTraits.push({
typeValue: '1 of 1',
value: tType,
category: 'Meta',
displayType: null,
});
}
});
return outTraits;
},
}, {
'mutant-ape-yacht-club': function (nftTraits) {
var outTraits = [];
var firstTrait = nftTraits[0].value;
var baseTrait = {
typeValue: 'Mutant Type',
id: '',
rarityTraitSum: 0,
traitCount: 0,
category: 'Meta',
displayType: null,
};
if (firstTrait.includes('M1')) {
outTraits.push(__assign(__assign({}, baseTrait), { value: 'M1' }));
}
return outTraits;
},
'deathbats-club': function (nftTraits) {
var outTraits = [];
nftTraits.forEach(function (trait) {
var tType = trait.typeValue;
if (['Brooks Wackerman', 'Johnny Christ', 'M. Shadows', 'Synyster Gates', 'Zacky Vengence', 'Zacky Vengeance', 'Shadows'].includes(tType) && !Object.keys(outTraits).includes('1 of 1')) {
outTraits.push({
typeValue: '1 of 1',
value: tType,
category: 'Meta',
displayType: null,
});
}
else if (firstTrait.includes('M2')) {
outTraits.push(__assign(__assign({}, baseTrait), { value: 'M2' }));
}
else {
outTraits.push(__assign(__assign({}, baseTrait), { value: 'M3' }));
}
return outTraits;
},
}, {
'ens': function (nftTraits) { return ensMetaFunc(nftTraits, 'ens'); },
}, {
'999club': function (nftTraits) { return ensMetaFunc(nftTraits, '999club'); },
});
return outTraits;
},
];
'mutant-ape-yacht-club': function (nftTraits) {
var outTraits = [];
var firstTrait = nftTraits[0].value;
var baseTrait = {
typeValue: 'Mutant Type',
id: '',
rarityTraitSum: 0,
traitCount: 0,
category: 'Meta',
displayType: null,
};
if (firstTrait.includes('M1')) {
outTraits.push(__assign(__assign({}, baseTrait), { value: 'M1' }));
}
else if (firstTrait.includes('M2')) {
outTraits.push(__assign(__assign({}, baseTrait), { value: 'M2' }));
}
else {
outTraits.push(__assign(__assign({}, baseTrait), { value: 'M3' }));
}
return outTraits;
},
'ens': function (nftTraits) { return ensMetaFunc(nftTraits, 'ens'); },
'999club': function (nftTraits) { return ensMetaFunc(nftTraits, '999club'); },
'100kclub': function (nftTraits) { return ensMetaFunc(nftTraits, '100kclub'); },
};
/**

@@ -294,0 +323,0 @@ * Get the "match" traits for a collection. Has some collection-specific logic to add desired

{
"name": "@poprank/rankings",
"version": "1.1.9",
"version": "1.1.10",
"description": "PopRank's NFT rarity and aesthetic ranking logic",

@@ -5,0 +5,0 @@ "publishConfig": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc