1.2.1 • Published 3 years ago

@epilogo/stringifyr v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Stringifyr

A polymorphic JS library for integrating with the Stringifyr platform.

ReactJS & ReactNative integration

import * as React from 'react';
import {StringifyrReact} from '@epilogo/stringifyr'

export const Stringifyr = StringifyrReact({
  react: { React },
  apiKey: 'REQUIRED_API_KEY',
  fetchOnLoadWithParams: {
    fileSlug: 'OPTIONAL_FILE_SLUG'
  },
});

The initialization above exposes some hooks to be used in your components.

Let's say we have a Stringifyr file with the following keys and values

{
  "blog.{lang=en}.{id=welcome}.title": "Welcome to my blog",
  "blog.{lang=en}.{id=welcome}.content": "...",
  "blog.{lang=en}.{id=tutorial}.title": "How to use Stringifyr",
  "blog.{lang=en}.{id=tutorial}.content": "..."
}

You can use useNodeValue to get all our blog posts in english

/**
 * Will resolve to 
 * posts = {
 *   welcome: {
 *     title: 'Welcome to my blog',
 *     content: '...',
 *   },
 *   tutorial: {
 *     title: 'How to use Stringifyr',
 *     content: '...',
 *   },
 * }
 */
const posts = Stringifyr.useNodeValue(`blog.{lang=en}.{id}`);

useNodeValue will return an object with keys whenever you provide an unresolved variable like {lang} or {id} and it will resolve the value when you define the variable. eg blog.en

If you provide the full path to a node only the string value will be returned. E.g blog.{lang=en}.{id=tutorial}.title will resolve to How to use Stringifyr.

/**
 * tutorialContent = "How to use Stringifyr"
 */
const tutorialContent = Stringifyr.useNodeValue(`blog.{lang=en}.{id=tutorial}.title`);

Pure HTML / JS integration

You can also include the library in other ways
Checkout the Skypack docs for more info

<!DOCTYPE html>
<html>
<script type="module">
    import Stringifyr from 'https://cdn.skypack.dev/@epilogo/stringifyr';

    new Stringifyr.StringifyrDOM({
        apiKey: "REQUIRED_API_KEY",
        fetchOnLoadWithParams: {
            fileSlug: 'OPTIONAL_FILE_SLUG'
        },
    });
</script>
<body>

<-- "{sfyr=blog.{lang=en}.title}" will be replaced with the related string value -->
<div>{sfyr=blog.{lang=en}.title}</div>

</body>
</html>
1.2.1

3 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

0.9.999

3 years ago

0.9.99

3 years ago

0.9.98

3 years ago

0.9.97

3 years ago

0.9.96

3 years ago

0.9.95

3 years ago

0.9.92

3 years ago

0.9.91

3 years ago

0.9.9

3 years ago

0.9.8

3 years ago

0.9.7

3 years ago

0.9.6

3 years ago

0.9.5

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.0

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago