1.1.1 • Published 2 years ago

dotlang v1.1.1

Weekly downloads
-
License
AGPL-3.0-or-later
Repository
github
Last release
2 years ago

Dotlang

Dotlang is a simple library for easily parsing and reading .lang files.

Installation

$ npm i dotlang

Usage

See the methods for more usage info.

Reading A File

const dotlang = require('dotlang')

const parsedFile = dotlang.parse("path/to/file.lang")
console.log(parsedFile)

Reading Multiple Files

const dotlang = require('dotlang')

const parsedFile = dotlang.parseMultiple(["path/to/file.lang", "path/to/anotherFile.lang"])
console.log(parsedFile)

Reading Entire Directory

const dotlang = require('dotlang')

const parsedFile = dotlang.parseDir("path/to/dir")
console.log(parsedFile) // Map(int) => { 'key' => 'value' }

Methods

parse(path: string): Map<string, string>

parses dotlang file and returns a map fo keys values.

ParametersTypeDescription
pathstringPath to .lang file
const parsed = dotlang.parse("path/to/file.lang")
console.log(parsed) // Map(int) => { 'fileName' => Map(int) { 'key' => 'value' } }

parseMultiple(paths: string[]): Map<string, Map<string, string>>

Parses multiple dotlang files and returns a map of file names with their corresponding keys/values

ParametersTypeDescription
pathstring[]Array of .lang file paths
const parsed = dotlang.parseMultiple(["path/to/file.lang", "path/to/anotherFile.lang"])
console.log(parsed) // Map(int) => { 'fileName' => Map(int) { 'key' => 'value' } }

parseDir(dir: string): Map<string, Map<string, string>>

Finds all lang files in specified dir and returns a map of file names with their corresponding keys/values

ParametersTypeDescription
dirstringPath to directory
const parsed = dotlang.parseDir("/path/to/dir")
console.log(parsed)

replaceTemplates(orig: string, ...replacements: any[]): string

Replaces templates in given string and return new string

ParametersTypeDescription
origstringOrignal string with %s templates
...replacementsany[]List of replacements
const str = "Hi my name is %s and I like %s"
const newStr = dotlang.replaceTemplates(str, "Nobu", "pizza")
console.log(newStr) // Hi my name is Nobu and I like pizza

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

AGPL-3.0

1.1.1

2 years ago

1.1.0

2 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