New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@companieshouse/ch-node-utils

Package Overview
Dependencies
Maintainers
8
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@companieshouse/ch-node-utils

set of node utils which can be used across repos/projects

  • 1.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
303
increased by2.36%
Maintainers
8
Weekly downloads
 
Created
Source

ch-node-utils

set of node utils which can be used across repos/projects. Available as a normal npm depndency(here on npmjs)

Areas for the different utilities stored in this repo:

i18n (Internationalisation)

Internationalisation has been added to CHS, after already being available (at least for Welsh) on legacy systems (EWF/SCRS/CHD/...)

The implementation is described in Confluence for both Java and Node.js services.

Some common utilities for Node.js are here provided. The chosen Node.js i18n library is i18next, which, at the time of writing, can be considered the standard:

Node.js i18n libs

Node.js i18n libs trend

  • i18nCh.ts: wrapper to i18next

  • languageNames.ts: to manage Language names and their associated ISO codes (iso-639). It mainly provides:

    • a function to get, from an array of submitted iso-codes, a structured array of iso-codes & native names.

    Ex:

    [... "en", "cy", ...]   ==> [ ... {"IsoCode": "en", "Name": "English" },  {"IsoCode": "cy", "Name": "Cymraeg" } ...]
    
    • a custom function to sort the supported locales (apart from leaving 'en' always at 1st position, it sorts alphabetically)
  • subDirs.ts: to manage files and dirs, so that i18n locales' folders can be sourced automatically. This allows for example to have an array of iso-codes if the ./locales dir follows the normal convention. Ex, this array of iso-codes [ "ar", "bn", "cy", "de", "en", "gd", "ja", "uk"] is retrieved from the following tree:

       │   ├── locales
       │   │   ├── ar
       │   │   │   ├── errors.json
       │   │   │   ├── global.json
       │   │   │   ├── landing.json
       │   │   │   ├── layout.json
       │   │   │   ├── search-company.json
       │   │   │   ├── view-company-information.json
       │   │   │   └── who-to-tell.json
       │   │   ├── bn
       │   │   │   └── *.json
       │   │   ├── cy
       │   │   │   └── *.json
       │   │   ├── de
       │   │   │   └── *.json
       │   │   ├── en
       │   │   │   └── *.json
       │   │   ├── gd
       │   │   │   └── *.json
       │   │   ├── ja
       │   │   │   └── *.json
       │   │   ├── uk
       │   │   │   └── *.json
    
  • manageLocales.middleware.ts: middleware that can be reused to manage locales while dealing with http requests.

  • add-lang-to-url.njk: to add the lang=xx query param to urls:

https://.....<self>....../?lang=cy

Auto add lang=xx

  • locales-banner.njk: to add the locales banner

locales banner

  • ENV VARS: the following ENV vars are used:
ENV VARDescription
CH_NODE_UTILS_DROP_LANG_QUERY_PARAMIt could be set to drop the lang="xx" query param from the current URL (see Example)
CH_NODE_UTILS_LOG_LVLIt could be set to "TRACE" or "DEBUG" (case insensitive) to dump internal info while inside ch-node-utils (see Example)

FAQs

Package last updated on 19 Mar 2024

Did you know?

Socket

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.

Install

Related posts

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