https://github.com/spoonx/field-string-parser
A field-string parser
https://github.com/spoonx/field-string-parser
Last synced: 4 months ago
JSON representation
A field-string parser
- Host: GitHub
- URL: https://github.com/spoonx/field-string-parser
- Owner: SpoonX
- License: mit
- Created: 2018-02-08T11:22:05.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-08T11:38:14.000Z (over 7 years ago)
- Last Synced: 2025-02-25T04:17:34.647Z (4 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/SpoonX/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.
```js
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.
```js
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