Categories
This is a JavaScript utility module that represents a category taxonomy (nested list)
for places people care about in the world, aka Points of Interest (POIs).
Categories represent the place type, for example a Starbucks is a coffee_shop
.
Usage
Install via npm or yarn
yarn add @streetcredlabs/categories
or
npm i --save @streetcredlabs/categories
Import/require in the JavaScript client code
const { findById } = require('@streetcredlabs/categories');
import { findById } from '@streetcredlabs/categories';
API
Languages
This TypeScript enum contains all available languages.
findById
This function allows the client to look up the category object by its id. Categories may be nested.
import { findById } from '@streetcredlabs/categories';
const category = findById(1);
{
"id": 1,
"name": "Arts & Entertainment",
"icon": "theatre",
"categories": [ <category> ]
}
Call with Languages[lang]
to get a certain category, with the name translated into the preferred language:
findById(9049, 'fil')
returns { id: 9049, name: 'Pasukan', icon: 'entrance', attributes: undefined }
dump
Returns the entire categories array.
import { dump } from "@streetcredlabs/categories";
const categories = dump();
[
{
"id": 1,
"name": "Arts & Entertainment",
"icon": "theatre",
"categories": [...]
},
...
]
Call with Languages[lang]
as a second argument to get translated data: dump('fil')
getCompleteness
Determines how complete a place is based on our scoring system.
import { getCompleteness } from '@streetcredlabs/categories';
const place = funcThatGetsAStandardPlaceObj();
console.log(getCompleteness(place));
Contributing to this project
Pull requests are warmly welcomed.
Clone the repo
git clone git@github.com:streetcredlabs/categories.git && cd categories
Install dependencies
yarn
Run tests and watch for changes:
yarn test-watch
Run tests once:
yarn test
Run build and watch for changes:
yarn start
Run build once:
yarn build
Generate translation files
yarn translations
Releasing
Release a new version of this module based off the version in package.json
. Note you will need to have publish access to the streetcredlabs
npm account and be authenticated.
yarn release
The script does a few things:
- Builds the
dist
version with yarn build
(⚠️ NOTE: This needs improvement. Right now, if this results in changes, they won't be committed and it could be weird) - Creates a new git tag from the
package.json
version - Attempts to publish to npm with
npm publish