npm.io
1.0.3 • Published 7 years ago

kivra-copy-consumer

Licence
ISC
Version
1.0.3
Deps
3
Size
27 kB
Vulns
0
Weekly
0

Kivra copy consumer

Reusable copy consumption logic for Kivra frontend services

Get started

npm i --save kivra-copy-consumer
import { fetchCopy } from 'kivra-copy-consumer'

fetchCopy({
  'en-US': 'https://example.com/us-copy.json'
},
{
  useBrowserLocale: true,
  fallbackLocale: 'en-US',
  defaultCopyPath: '/copy-default.json'
}).then(copy => {
  // use copy ...
})
Which locale is used?

In order of prioritization:

  • if locale GET param is set in URL, copy is fetched for that locale
  • if useBrowserLocale is true, use locale prefered by browser
  • otherwise use fallbackLocale
Which file is fetched
  • If an url for the chosen locale was passed then that is fetched. If the fetch fails we instead fetch defaultCopyPath.
  • If no url for the chosen locale was passed then the url for fallbackLocale is fetched