Skip to content

SpoonX/field-string-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Field string parser

A library that consumes strings and converts them into string definitions.

Additionally, it formats and adds an argument string for easy code generating.

Installation

npm i --save field-string-parser or yarn add field-string-parser

Usage

Usage is pretty straight forward. You can reuse instances, or use the static method.

Fields can be passed in using JSON, or the ezon format.

Examples of valid formats:

'username,password:(size:50),active:boolean'

or

'username:string,password:field(size:50),active:field(type:boolean)'

Static example

Here's an example using the static parse method.

const parsedFields = FieldStringParser.parse('username,password:(size:50),active:boolean');

console.log(parsedFields);

// Generates the following
{
  username: {
    argumentString: '{ type: \'string\' }',
    definition    : { type: 'string' }
  },
  password: {
    argumentString: '{ size: 50, type: \'string\' }',
    definition    : { size: 50, type: 'string' }
  },
  active  : {
    argumentString: '{ type: \'boolean\' }',
    definition    : { type: 'boolean' }
  }
}

Instance example

Here's an example using the instance approach.

const fieldParser  = new FieldParser('username,password:(size:50),active:boolean');
const parsedFields = fieldStringParser.parse();

console.log(parsedFields);

// Generates the following
{
  username: {
    argumentString: '{ type: \'string\' }',
    definition    : { type: 'string' }
  },
  password: {
    argumentString: '{ size: 50, type: \'string\' }',
    definition    : { size: 50, type: 'string' }
  },
  active  : {
    argumentString: '{ type: \'boolean\' }',
    definition    : { type: 'boolean' }
  }
}

License

MIT

About

A field-string parser

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published