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

@azuro-org/dictionaries

Package Overview
Dependencies
Maintainers
3
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@azuro-org/dictionaries - npm Package Compare versions

Comparing version 1.0.10 to 2.0.0

.tmp/dictionaries/gamePeriods.js

83

dist/index.es.js
var MARKET_IDS___DONT_GROUP_MARKETS_BY_TEAM_PLAYER_ID = [3];
var MARKET_IDS___USE_TEAM_PLAYER_INSTEAD_OUTCOME = [3];var assembleSelectionName = function (outcomeId, dictionaries, params) {
var outcomes = dictionaries.outcomes, selections = dictionaries.selections, teamPlayers = dictionaries.teamPlayers, points = dictionaries.points;
var _a = outcomes[outcomeId], marketId = _a.marketId, selectionId = _a.selectionId, teamPlayerId = _a.teamPlayerId, pointsId = _a.pointsId;
var selection = selections[selectionId];
var teamPlayer = teamPlayers[teamPlayerId];
var point = points[pointsId];
var selectionName = selection;
if (teamPlayer
&& MARKET_IDS___USE_TEAM_PLAYER_INSTEAD_OUTCOME.includes(marketId)) {
selectionName = teamPlayer;
}
if ((params === null || params === void 0 ? void 0 : params.withPoint) && point !== undefined) {
selectionName += " (".concat(point, ")");
}
return selectionName;
};var assembleMarketName = function (outcomeId, dictionaries) {
var outcomes = dictionaries.outcomes, markets = dictionaries.markets, gamePeriods = dictionaries.gamePeriods, gameTypes = dictionaries.gameTypes, teamPlayers = dictionaries.teamPlayers;
var _a = outcomes[outcomeId], marketId = _a.marketId, gamePeriodId = _a.gamePeriodId, gameTypeId = _a.gameTypeId, teamPlayerId = _a.teamPlayerId;
var gamePeriod = gamePeriods[gamePeriodId] ? "".concat(gamePeriods[gamePeriodId], " - ") : '';
var teamPlayer = teamPlayers[teamPlayerId];
var market = markets[marketId];
var gameType = gameTypes[gameTypeId];
var rightPart = [teamPlayer, market, gameType].filter(Boolean).join(' ');
return "".concat(gamePeriod).concat(rightPart);
};var getMarketKey = function (outcomeId, dictionaries) {
var _a = dictionaries.outcomes[outcomeId], marketId = _a.marketId, gamePeriodId = _a.gamePeriodId, gameTypeId = _a.gameTypeId, teamPlayerId = _a.teamPlayerId;
var MARKET_IDS___USE_TEAM_PLAYER_INSTEAD_OUTCOME = [3];var getMarketKey = function (props) {
var _a = props.dictionaries.outcomes[props.outcomeId], marketId = _a.marketId, gamePeriodId = _a.gamePeriodId, gameTypeId = _a.gameTypeId, teamPlayerId = _a.teamPlayerId;
// ATTN very important to not change the order of params in the literal!

@@ -36,13 +12,52 @@ // same logic used for static keys in helpers/conditions/marketRegistry.ts

return marketKeys.join('-');
};var getMarketName = function (outcomeId, dictionaries) {
var marketNames = dictionaries.marketNames;
var marketKey = getMarketKey(outcomeId, dictionaries);
};var getMarketName = function (props) {
var _a = props.dictionaries, marketNames = _a.marketNames, markets = _a.markets, gamePeriods = _a.gamePeriods, gameTypes = _a.gameTypes, teamPlayers = _a.teamPlayers;
var marketKey;
if (props.outcomeId) {
marketKey = getMarketKey({
outcomeId: props.outcomeId,
dictionaries: props.dictionaries,
});
}
else {
marketKey = props.marketKey;
}
if (marketNames[marketKey]) {
return marketNames[marketKey];
}
return assembleMarketName(outcomeId, dictionaries);
};var getMarketDescription = function (outcomeId, dictionaries) {
var marketDescriptions = dictionaries.marketDescriptions;
var marketKey = getMarketKey(outcomeId, dictionaries);
var _b = marketKey.split('-'), marketId = _b[0], gamePeriodId = _b[1], gameTypeId = _b[2], teamPlayerId = _b[3];
var gamePeriod = gamePeriods[gamePeriodId] ? "".concat(gamePeriods[gamePeriodId], " - ") : '';
var teamPlayer = teamPlayers[teamPlayerId];
var market = markets[marketId];
var gameType = gameTypes[gameTypeId];
var rightPart = [teamPlayer, market, gameType].filter(Boolean).join(' ');
return "".concat(gamePeriod).concat(rightPart);
};var getMarketDescription = function (props) {
var marketDescriptions = props.dictionaries.marketDescriptions;
var marketKey;
if (props.outcomeId) {
marketKey = getMarketKey({
outcomeId: props.outcomeId,
dictionaries: props.dictionaries,
});
}
else {
marketKey = props.marketKey;
}
return marketDescriptions[marketKey];
};var getSelectionName = assembleSelectionName;export{assembleMarketName,assembleSelectionName,getMarketDescription,getMarketKey,getMarketName,getSelectionName};
};var getSelectionName = function (props) {
var _a = props.dictionaries, outcomes = _a.outcomes, selections = _a.selections, teamPlayers = _a.teamPlayers, points = _a.points;
var _b = outcomes[props.outcomeId], marketId = _b.marketId, selectionId = _b.selectionId, teamPlayerId = _b.teamPlayerId, pointsId = _b.pointsId;
var selection = selections[selectionId];
var teamPlayer = teamPlayers[teamPlayerId];
var point = points[pointsId];
var selectionName = selection;
if (teamPlayer
&& MARKET_IDS___USE_TEAM_PLAYER_INSTEAD_OUTCOME.includes(marketId)) {
selectionName = teamPlayer;
}
if ((props === null || props === void 0 ? void 0 : props.withPoint) && point !== undefined) {
selectionName += " (".concat(point, ")");
}
return selectionName;
};export{getMarketDescription,getMarketKey,getMarketName,getSelectionName};
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var MARKET_IDS___DONT_GROUP_MARKETS_BY_TEAM_PLAYER_ID = [3];
var MARKET_IDS___USE_TEAM_PLAYER_INSTEAD_OUTCOME = [3];var assembleSelectionName = function (outcomeId, dictionaries, params) {
var outcomes = dictionaries.outcomes, selections = dictionaries.selections, teamPlayers = dictionaries.teamPlayers, points = dictionaries.points;
var _a = outcomes[outcomeId], marketId = _a.marketId, selectionId = _a.selectionId, teamPlayerId = _a.teamPlayerId, pointsId = _a.pointsId;
var selection = selections[selectionId];
var teamPlayer = teamPlayers[teamPlayerId];
var point = points[pointsId];
var selectionName = selection;
if (teamPlayer
&& MARKET_IDS___USE_TEAM_PLAYER_INSTEAD_OUTCOME.includes(marketId)) {
selectionName = teamPlayer;
}
if ((params === null || params === void 0 ? void 0 : params.withPoint) && point !== undefined) {
selectionName += " (".concat(point, ")");
}
return selectionName;
};var assembleMarketName = function (outcomeId, dictionaries) {
var outcomes = dictionaries.outcomes, markets = dictionaries.markets, gamePeriods = dictionaries.gamePeriods, gameTypes = dictionaries.gameTypes, teamPlayers = dictionaries.teamPlayers;
var _a = outcomes[outcomeId], marketId = _a.marketId, gamePeriodId = _a.gamePeriodId, gameTypeId = _a.gameTypeId, teamPlayerId = _a.teamPlayerId;
var gamePeriod = gamePeriods[gamePeriodId] ? "".concat(gamePeriods[gamePeriodId], " - ") : '';
var teamPlayer = teamPlayers[teamPlayerId];
var market = markets[marketId];
var gameType = gameTypes[gameTypeId];
var rightPart = [teamPlayer, market, gameType].filter(Boolean).join(' ');
return "".concat(gamePeriod).concat(rightPart);
};var getMarketKey = function (outcomeId, dictionaries) {
var _a = dictionaries.outcomes[outcomeId], marketId = _a.marketId, gamePeriodId = _a.gamePeriodId, gameTypeId = _a.gameTypeId, teamPlayerId = _a.teamPlayerId;
var MARKET_IDS___USE_TEAM_PLAYER_INSTEAD_OUTCOME = [3];var getMarketKey = function (props) {
var _a = props.dictionaries.outcomes[props.outcomeId], marketId = _a.marketId, gamePeriodId = _a.gamePeriodId, gameTypeId = _a.gameTypeId, teamPlayerId = _a.teamPlayerId;
// ATTN very important to not change the order of params in the literal!

@@ -36,13 +12,52 @@ // same logic used for static keys in helpers/conditions/marketRegistry.ts

return marketKeys.join('-');
};var getMarketName = function (outcomeId, dictionaries) {
var marketNames = dictionaries.marketNames;
var marketKey = getMarketKey(outcomeId, dictionaries);
};var getMarketName = function (props) {
var _a = props.dictionaries, marketNames = _a.marketNames, markets = _a.markets, gamePeriods = _a.gamePeriods, gameTypes = _a.gameTypes, teamPlayers = _a.teamPlayers;
var marketKey;
if (props.outcomeId) {
marketKey = getMarketKey({
outcomeId: props.outcomeId,
dictionaries: props.dictionaries,
});
}
else {
marketKey = props.marketKey;
}
if (marketNames[marketKey]) {
return marketNames[marketKey];
}
return assembleMarketName(outcomeId, dictionaries);
};var getMarketDescription = function (outcomeId, dictionaries) {
var marketDescriptions = dictionaries.marketDescriptions;
var marketKey = getMarketKey(outcomeId, dictionaries);
var _b = marketKey.split('-'), marketId = _b[0], gamePeriodId = _b[1], gameTypeId = _b[2], teamPlayerId = _b[3];
var gamePeriod = gamePeriods[gamePeriodId] ? "".concat(gamePeriods[gamePeriodId], " - ") : '';
var teamPlayer = teamPlayers[teamPlayerId];
var market = markets[marketId];
var gameType = gameTypes[gameTypeId];
var rightPart = [teamPlayer, market, gameType].filter(Boolean).join(' ');
return "".concat(gamePeriod).concat(rightPart);
};var getMarketDescription = function (props) {
var marketDescriptions = props.dictionaries.marketDescriptions;
var marketKey;
if (props.outcomeId) {
marketKey = getMarketKey({
outcomeId: props.outcomeId,
dictionaries: props.dictionaries,
});
}
else {
marketKey = props.marketKey;
}
return marketDescriptions[marketKey];
};var getSelectionName = assembleSelectionName;exports.assembleMarketName=assembleMarketName;exports.assembleSelectionName=assembleSelectionName;exports.getMarketDescription=getMarketDescription;exports.getMarketKey=getMarketKey;exports.getMarketName=getMarketName;exports.getSelectionName=getSelectionName;
};var getSelectionName = function (props) {
var _a = props.dictionaries, outcomes = _a.outcomes, selections = _a.selections, teamPlayers = _a.teamPlayers, points = _a.points;
var _b = outcomes[props.outcomeId], marketId = _b.marketId, selectionId = _b.selectionId, teamPlayerId = _b.teamPlayerId, pointsId = _b.pointsId;
var selection = selections[selectionId];
var teamPlayer = teamPlayers[teamPlayerId];
var point = points[pointsId];
var selectionName = selection;
if (teamPlayer
&& MARKET_IDS___USE_TEAM_PLAYER_INSTEAD_OUTCOME.includes(marketId)) {
selectionName = teamPlayer;
}
if ((props === null || props === void 0 ? void 0 : props.withPoint) && point !== undefined) {
selectionName += " (".concat(point, ")");
}
return selectionName;
};exports.getMarketDescription=getMarketDescription;exports.getMarketKey=getMarketKey;exports.getMarketName=getMarketName;exports.getSelectionName=getSelectionName;
{
"name": "@azuro-org/dictionaries",
"version": "1.0.10",
"version": "2.0.0",
"description": "CLI and set of helpers to work with Azuro protocol dictionaries",
"bin": "bin.js",
"homepage": "https://github.com/Azuro-protocol/dictionaries/blob/main/packages/dictionaries",
"author": "",
"license": "ISC",
"repository": {
"type": "git",
"url": "git+https://github.com/Azuro-protocol/dictionaries.git"
},
"bugs": {
"url": "https://github.com/Azuro-protocol/dictionaries/issues"
},
"keywords": [
"azuro",
"dictionaries",
"helpers",
"cli"
],
"module": "dist/index.es.js",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"bin": {
"get-dictionaries": "bin/get-dictionaries.js",
"get-outcomes": "bin/get-outcomes.js"
},
"scripts": {

@@ -13,19 +32,5 @@ "dev": "rollup -cw",

"prepublishOnly": "npm run build",
"test-bin": "rimraf ./out && node ./bin -v latest -o ./out -t ts"
"test-get-dictionaries": "rimraf ./test-out && node ./bin/get-dictionaries.js -v latest -o ./test-out -t arrays",
"test-get-outcomes": "node ./bin/get-outcomes.js --market 'Full Time Result'"
},
"keywords": [
"dictionaries",
"helpers",
"cli"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Azuro-protocol/dictionaries.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Azuro-protocol/dictionaries/issues"
},
"homepage": "https://github.com/Azuro-protocol/dictionaries/blob/main/packages/dictionaries",
"devDependencies": {

@@ -32,0 +37,0 @@ "@babel/core": "^7.17.0",

# Dictionaries Package
This package provides 2 features: CLI to download dictionaries; helpers to work with dictionaries.
The Azuro Dictionaries package is designed to provide easy access to the Azuro Protocol dictionaries, which contain
mappings between IDs and human-readable strings. The package includes several CLI and helpers to make it easy to work with
these dictionaries in your project.

@@ -9,118 +11,139 @@

```bash
npm i --save @azuro-org/dictionaries
npm install @azuro-org/dictionaries
```
## CLI
## CLI `get-dictionaries`
All dictionaries stored in [public repository](https://github.com/Azuro-protocol/public-config/tree/main/dictionaries).
For ease of use, the dictionaries have a version and file format.
All dictionaries are stored in a [public repository](https://github.com/Azuro-protocol/public-config/tree/main/dictionaries)
on GitHub. To download them use CLI.
It's easy to download dictionary files with CLI. In your package.json add script:
In your `package.json` file, add the following script:
```json
"scripts": {
"get-dicts": "dictionaries -o {OUTPUT_DIR} -v {VERSION} -t {FILES_TYPE}"
}
"get-dictionaries": "get-dictionaries -o {OUTPUT_DIR} -v {VERSION} -t {FILES_TYPE}"
```
- `VERSION` is the version of downloaded dictionaries. [Check versions](https://github.com/Azuro-protocol/public-config/tree/main/dictionaries).
- `OUTPUT_DIR` is the directory where to put downloaded files.
- `FILES_TYPE` is the extension of downloaded files. Accepts `ts`, `js`, `maps`, `arrays`. `maps` and `arrays` are
json files with different output format.
Replace the following placeholders:
**Examples**
- `{OUTPUT_DIR}`: the directory where to store the downloaded files.
- `{VERSION}`: the version of the dictionaries to download (use `latest` for the latest version).
- `{FILES_TYPE}`: the file format (`ts`, `js`, `maps` or `arrays`)
```bash
dictionaries -o ./dist -v 2.0.7 -t ts # will download v2.0.7 typescript files to ./dist directory
## CLI `get-outcomes`
If you need to get a list of `outcomeId`s related to a specific market name, you can use the `get-outcomes` command.
For example:
```
get-outcomes --market 'Full Time Result'
```
Use `latest` value for the version param to download the latest dictionaries update.
This will return an array of `outcomeId`s that are related to the specified market.
```bash
dictionaries -o ./dist -v latest -t js # will download latest javascript files to ./dist directory
You can use this list to filter conditions in a GraphQL query, like this:
```graphql
query Games($filterConditions: Condition_Filter!) {
games {
conditions(where: $filterConditions) {
conditionId
core {
address
}
outcomes {
outcomeId
odds
}
}
}
}
```
```ts
const outcomeIds = [ '29', '30', '31', '6983', '6984' ] // taken from the result of the command execution
useQuery(GAMES_QUERY, {
variables: {
filterConditions: {
outcomes_: {
outcomeId_in: outcomeIds
}
}
}
})
```
## Helpers
```js
import { getMarketKey, getMarketName, getMarketDescription, assembleMarketName, assembleSelectionName } from '@azuro-org/dictionaries'
```
### Usage
### Get market name and description
To use the package in your project, you can import the desired helpers from the package:
```js
import { getMarketKey } from '@azuro-org/dictionaries'
import dictionaries from './path-to-downloaded-dictionaries'
const outcomeId = 1
const marketKey = getMarketKey(outcomeId, dictionaries)
import { getMarketKey, getMarketName, getMarketDescription, getSelectionName } from '@azuro-org/dictionaries'
```
`getMarketKey(outcomeId, dictionaries)` returns the string key `marketId-gamePeriodId-gameTypeId[-teamPlayerId]`
built from the dictionaries related to passed `outcomeId`.
The package provides the following helpers:
In the example above the result is `1-1-1`.
### `getMarketKey`
There are two dictionary files `marketNames.js` and `marketDescriptions.js`. `marketKey` is used to receive market name
and description for specific outcome ID.
This function generates a string `marketKey` from an `outcomeId`. A `marketKey` is a combination of other IDs, including
the `marketId`, `gamePeriodId`, `gameTypeId`, and `teamPlayerId` (if applicable). This function takes an object with
the `outcomeId` and `dictionaries` as properties.
```js
import dictionaries from './path-to-downloaded-dictionaries'
dictionaries.marketNames['1-1-1'] // "Full Time Result"
dictionaries.marketDescriptions['1-1-1'] // "You predict the result..."
getMarketKey({ outcomeId: '1', dictionaries }) // "1-1-1"
```
**!!! Note that there are no texts for each `outcomeId` !!!**
### `getMarketName`
`marketNames[marketKey]` and `marketDescriptions[marketKey]` may return `undefined`. For `marketName` generation there
is other helper `assembleMarketName`. It generates human readable market name based on outcome `marketId`, `gamePeriodId`,
`gameTypeId`, `teamPlayerId`.
This function returns the human-readable name of the market related to an `outcomeId` or a `marketKey`. This function takes
an object with either the `outcomeId` or `marketKey` and `dictionaries` as properties.
```js
import { getMarketKey, assembleMarketName } from '@azuro-org/dictionaries'
import dictionaries from './path-to-downloaded-dictionaries'
getMarketName({ outcomeId: '1', dictionaries }) // "Full Time Result"
getMarketName({ marketKey: '1-1-1', dictionaries }) // "Full Time Result"
```
const outcomeId = 42
const marketKey = getMarketKey(outcomeId, dictionaries)
### `getMarketDescription`
let marketName = dictionaries[marketKey] // undefined
This function returns the human-readable description of the market related to an `outcomeId` or a `marketKey`. This
function takes an object with either the `outcomeId` or `marketKey` and `dictionaries` as properties.
if (!marketName) {
marketName = assembleMarketName(outcomeId, dictionaries) // "Whole game - Winner of match Goal"
}
```js
getMarketDescription({ outcomeId: '1', dictionaries }) // "You predict the result..."
getMarketDescription({ marketKey: '1-1-1', dictionaries }) // "You predict the result..."
```
There are additional 2 sugar helpers:
It's important to note that not all `outcomeId` values have a corresponding market name or description. If the name
doesn't exist in the dictionaries, the helper function will return a concatenated string of values taken from the
`marketId`, `gamePeriodId`, `gameTypeId`, and `teamPlayerId` IDs.
```js
import { getMarketName } from '@azuro-org/dictionaries'
import dictionaries from './path-to-downloaded-dictionaries'
In cases where there is no market name for the provided `outcomeId`, the helper function will return `undefined`. It's
important to keep this in mind when using these helper functions to avoid any unexpected behavior.
getMarketName(1, dictionaries) // "Full Time Result"
getMarketName(42, dictionaries) // "Whole game - Winner of match Goal"
```
### `getSelectionName`
This function returns the human-readable name of the selection related to an `outcomeId`. This function takes an object
with the `outcomeId`, `dictionaries` and `withPoint` (if applicable) as properties.
```js
import { getMarketDescription } from '@azuro-org/dictionaries'
import dictionaries from './path-to-downloaded-dictionaries'
getMarketDescription(1, dictionaries) // "You predict the result..."
getMarketDescription(42, dictionaries) // undefined. Note that there is no `assemblyMarketDescription` helper.
getSelectionName({ outcomeId: '1', dictionaries }) // "Yes"
getSelectionName({ outcomeId: '4', dictionaries }) // "Team 2"
getSelectionName({ outcomeId: '4', dictionaries, withPoint: true }) // "Team 2 (4.5)"
```
### Get selection (outcome) name
### Example
```js
import { getSelectionName } from '@azuro-org/dictionaries'
import dictionaries from './dist'
import { getMarketName, getSelectionName } from '@azuro-org/dictionaries'
import dictionaries from './path/to/dictionaries'
const outcomeId = 1
const selectionName = getSelectionName(outcomeId, dictionaries) // "Yes"
const outcomeId = 4
const selectionName = getSelectionName(outcomeId, dictionaries) // "Team 2"
const selectionName = getSelectionName(outcomeId, dictionaries, { withPoint: true }) // "Team 2 (4.5)"
const marketKey = getMarketKey({ outcomeId: '123', dictionaries })
const marketName = getMarketName({ marketKey, dictionaries })
const selectionName = getSelectionName({ outcomeId: '123', dictionaries })
```
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