g3kon

Centralized content store

  • g3kon

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
g3kon
002.0.03 years ago3 years agoMinified + gzip package size for g3kon in KB

Readme

g3kon
!npm packagenpm-imgnpm-url !Build Statusbuild-imgbuild-url !Downloadsdownloads-imgdownloads-url !Issuesissues-imgissues-url !Code Coveragecodecov-imgcodecov-url !Commitizen Friendlycommitizen-imgcommitizen-url !Semantic Releasesemantic-release-imgsemantic-release-url
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

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 function

  • returns {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 key

  • returns {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.