Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

data-file-parser

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-file-parser

node module for parsing file and writing into another file

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

NPM

data-file-parser

parse data from file using regular expression (regex)

Getting Started

This plugin requires Grunt ~0.4.0

you may install this module with this command:

npm install data-file-parser --save-dev

after instalation you can load it like so

var dataFileParser = require('data-file-parser');

dataFileParser.parse(params)

Returns: Q promise object

options

in

Type: String
Required

path to input file wich will be parsed

encoding

Type: String
Default: utf8

encoding in which input file is written this option is passed to fs.readFile function

out

Type: String
Required

path to output file in wich parsed data will be written

regex

Type: RegExp Required Example:/^([a-z]+) ([a-z]+). (.+)/gim,

using this regular expresion will be parsed input file. you should use at list one group in it.

as

Type: String
Required Example: 'word|type|desc' it should contain keys (seperated using '|' ) of parsed data using thous keys will be generated date items in output.

var

Type: String
Default: false

name of variable to wich parsed data vill be esigned and will be written. it should be saved as '*.js' file and then included using script tag so thet variable vill be available

Usage example

this is content of words.txt

abase v. To lower in position, estimation, or the like;
abbess n. The lady superior of a nunnery. 
abbey n. The group of buildings which collectively form the dwelling-place of a society of monks or nuns.
abbot n. The superior of a community of monks. 
abdicate v. To give up (royal power or the like). 
abdomen n. In mammals, the visceral cavity between the diaphragm and the pelvic floor; the belly. 
abdominal n. Of, pertaining to, or situated on the abdomen. 
abduction n. A carrying away of a person against his will, or illegally. 

this is index.js

var dataParser = require('data-file-parser');
dataParser.parse({
    in: 'words.txt',    //input file
    out: 'words.js',    //output file
    var:'words',        //variable name
    // g for global 
    // i for ignore case
    // m fot ^ to be start of every line not whole string
    regex: /^([a-z\-]+) ([a-z]+)\. (.+)/gim,
    as:'word|type|desc' //object keys
}).then(function(arr){
    console.log(arr.length+" words");
})

so after runing it

node index.js

this will be in wors.js

var words = [
    {
        "word": "abase",
        "type": "v",
        "desc": "To lower in position, estimation, or the like;"
    },
    {
        "word": "abbess",
        "type": "n",
        "desc": "The lady superior of a nunnery. "
    },
    {
        "word": "abbey",
        "type": "n",
        "desc": "The group of buildings which collectively form the dwelling-place of a society of monks or nuns."
    },
    {
        "word": "abbot",
        "type": "n",
        "desc": "The superior of a community of monks. "
    },
    {
        "word": "abdicate",
        "type": "v",
        "desc": "To give up (royal power or the like). "
    },
    {
        "word": "abdomen",
        "type": "n",
        "desc": "In mammals, the visceral cavity between the diaphragm and the pelvic floor; the belly. "
    },
    {
        "word": "abdominal",
        "type": "n",
        "desc": "Of, pertaining to, or situated on the abdomen. "
    },
    {
        "word": "abduction",
        "type": "n",
        "desc": "A carrying away of a person against his will, or illegally. "
    }
];

and it will be ready to use in your static web project or whatever

// Project configuration.
<script src="words.js"></script>
<script>
    console.log(words.length);
</script>

Release History

  • 2013-12-28   v0.0.2   add content to readme.md
  • 2013-12-28   v0.0.1   it just works :D

author Irakli Safareli

Keywords

FAQs

Package last updated on 28 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc