Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@streetcredlabs/categories
Advanced tools
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
.
yarn add @streetcredlabs/categories
or
npm i --save @streetcredlabs/categories
// using CommonJS
const { findById } = require('@streetcredlabs/categories');
// using ES6
import { findById } from '@streetcredlabs/categories';
The following top-level exports are available:
This TypeScript enum contains all available languages.
> const cats = require('./dist/bundle')
undefined
> `The following languages are available: ${Object.keys(cats.Languages).join(', ')}`
'The following languages are available: en, fil, id, ms, th, vi, zh-Hans'
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 }
Parameters:
language
(defaults to en
): one of the available language codes found in the Languages
enumsortAlphabetically
(defaults to true
): whether or not to sort categories using a language-aware sorterReturns 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')
Determines how complete a place is based on our scoring system.
import { getCompleteness } from '@streetcredlabs/categories';
const place = funcThatGetsAStandardPlaceObj();
console.log(getCompleteness(place)); // 0.75
Pull requests are warmly welcomed.
This project uses lingui
to generate gettext-format .po
files containing all of the category names.
As an example, here's how to add a translation for the language Ido, which uses the code io
.
The first step to add a new translation is to use lingui
to add a new locale and extract existing strings:
yarn lingui add-locale io
yarn lingui extract io
The first command will create a stub translation file in src/locales/io/messages.po
and the second command will append all translatable strings into that file. Provide a translator with the messages.po
, and have them fill in the msgstr ""
s with translations of the preceeding msgid "..."
s.
Once all of the translations are done, transform the po
-file into the Lingui format:
yarn lingui compile --typescript
Include the completed translation in the library by adding it to src/index.ts
:
diff --git a/src/index.ts b/src/index.ts
index e260261..7ad39f6 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -7,6 +7,7 @@ import ms from './locales/ms/messages';
import th from './locales/th/messages';
import vi from './locales/vi/messages';
import zhHans from './locales/zh-Hans/messages';
+import io from './locales/io/messages';
import categories from './data/categories';
import getCompletenessUtil from './utils/getCompleteness';
@@ -20,6 +21,7 @@ const catalogs = {
th,
vi,
'zh-Hans': zhHans,
+ io,
};
// Some shared types
Finally, run yarn build
and give it a test run:
bc@bifurcaria:~/streetcred/categories$ node
Welcome to Node.js v12.6.0.
Type ".help" for more information.
> const cats = require('./dist/bundle')
undefined
> cats.findById(9001, 'io')
{ id: 9001, name: 'Aero', icon: 'airport', attributes: undefined }
>
The translations
package script is a shortcut for extracting and compiling translations. It should be used after categories are added or modified, or if existing translations' po
-files have been updated.
git clone git@github.com:streetcredlabs/categories.git && cd categories
yarn
yarn test-watch
yarn test
yarn start
yarn build
yarn translations
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:
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)package.json
versionnpm publish
FAQs
JS utility wrapper for places category taxonomy
The npm package @streetcredlabs/categories receives a total of 3 weekly downloads. As such, @streetcredlabs/categories popularity was classified as not popular.
We found that @streetcredlabs/categories demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.