trophyutil
v7.6.0
Published
Isomorphic library of specialized trophy utilities
Downloads
283
Maintainers
Readme
TrophyUtil
TrophyUtil is a specialized utility library designed for parsing, modelling, and manipulating core PSNProfiles (PSNP) entities like trophies, games, and game series.
Features
- Isomorphic, working seamlessly in both frontend and backend (via jsdom) projects.
- Compatible with both CommonJS and ESM.
- HTML parsers for core PSNP entities like trophies, games, and game series.
- Richly-annotated interfaces and classes that provide helpful methods, like transforming a completion time into a timestamp and vice versa.
- Additional interfaces for MongoDB/Mongoose provide smoother database integration with properties like
createdAt
andupdatedAt
. - Specialized utility functions for trophy-specific use cases like parsing formatted numbers and checking for relative equality between entities.
Installation
Install TrophyUtil using npm:
npm install trophyutil
Usage
Here's how you might use this library to parse games, for example:
import {getPsnpPageType, PsnpGameStandard, ParserGameStandard} from 'trophyutil';
// Select nodes based on page type
const pageType = getPsnpPageType(window.location);
const gameNodes = PsnpGameStandard.getGameNodes(pageType, window.document);
// Parse nodes into richly-interfaced data
const parser = new ParserGameStandard();
const gameData = gameNodes.map(node => parser.parse(node));
const speed = gameData[0].completionSpeed; // 3661
// Classes wrap data with utility methods
const games = gameData.map(data => new PsnpGameStandard(data));
const speedString = PsnpGameStandard.secondsToSpeedString(speed); // "1 hour, 1 minute"
Contributing
Contributions are welcome! Submit a pull request or create an issue to contribute to this project.
License
This project is licensed under the GPLv3 License - see COPYING.txt
for details.