2.0.0 • Published 3 years ago
g3kon v2.0.0
g3kon
g3kon is centralized content store built with Typescript. g3kon is inspired by i18next, but rather than internationalization, g3kon focuses more on centralization
Install
Install with npm:
$ npm install g3kon
Usage example
import { G3kon } from 'g3ckon';
const g3kon = new G3kon({
contents: {
general: {
hello_world: 'Hello World!',
},
},
});
console.log(g3kon.g('general.hello_world'));
// => "Hello World!"
You can also have dynamic content with functions!
import { G3kon } from 'g3ckon';
const g3kon = new G3kon({
contents: {
general: {
welcome: (name: string) => `Welcome ${name}!`,
},
},
});
console.log(g3kon.g('general.welcome', ['Bob']));
// => "Welcome Bob!"
API
G3kon
Initialize a new G3kon
with the given options
data.
Params
options
{Object}: See all available options.
Example
import { G3kon } from 'g3ckon';
new G3kon({
contents: {},
});
.g
Get value
from key
Params
key
{String}args
{Array}: Arguments for interpolation function, not required if key doesnt map to a non interpolation functionreturns
{String | Number}: Value that key maps to.
Example
const g3kon = new G3kon({
contents: {
general: {
hello_world: 'Hello World!',
welcome: (name: string) => `Welcome ${name}`,
},
},
});
g3kon.g('general.hello_world');
// => "Hello World!"
g3kon.g('general.welcome', ['Bob']);
// => "Welcome Bob!"
.getFixedG
Get value
from key
Params
(Optional)
prefix
{String}: Prefix for the keyreturns
{Function}: Get function similar to.g
Example
const g3kon = new G3kon({
contents: {
general: {
hello_world: 'Hello World!',
welcome: (name: string) => `Welcome ${name}`,
},
},
});
// with prefix
const generalG = g3kon.getFixedG('general');
generalG('hello_world');
// => "Hello World!"
generalG('welcome', ['Bob']);
// => "Welcome Bob!"
// without prefix
const g = g3kon.getFixedG('general');
// same as g3kon.g
g('general.hello_world');
// => "Hello World!"
g('general.welcome', ['Bob']);
// => "Welcome Bob!"
Options
Option | Type | Required | Description |
---|---|---|---|
contents | object | true | Object from which are keys generated and values retrieved. |
Example
const g3kon = new G3kon({
contents: {
general: {
hello_world: 'Hello World!',
welcome: (name: string) => `Welcome ${name}`,
},
},
});
License
Copyright © 2021, Mortynex. Released under the MIT License.
2.0.0
3 years ago