GithubHelp home page GithubHelp logo

g3kon's Introduction

g3kon

npm package Build Status Downloads Issues Code Coverage Commitizen Friendly Semantic Release

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.

g3kon's People

Contributors

mortynex avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.