1.0.3 • Published 5 years ago

kivra-copy-consumer v1.0.3

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

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