Giter VIP home page Giter VIP logo

parse-listing's Introduction

parse-listing Build Status

Simple library that parses file listing input for different platforms. An example file listing is the output of the ls command in unix, or the dir command in DOS/Windows platforms.

Example

var Parser = require("parse-listing");

// Yeah yeah, multiline strings would make Crockford mad, I know.
var str = "drwxr-xr-x    5 1001     1001         4096 Jan 09 11:52 .\r\n\
drwxr-xr-x    4 0        0            4096 Sep 19 13:50 ..\r\n\
-rw-------    1 1001     1001         1118 Jan 09 12:09 .bash_history\r\n\
-rw-------    1 1001     1001          943 Jan 09 11:52 .viminfo\r\n\
drwxrwxr-x    5 1001     1001         4096 Jan 09 11:52 inaccessible\r\n\
drwxrwxrwx    2 1001     1001         4096 Sep 21 11:20 project1\r\n\
drwx------    2 1001     1001         4096 Oct 19 16:17 project2\r\n";

Parser.parseEntries(str, function(err, entryArray) {
  entryArray.forEach(function(entry, i) {
    console.log("Name:",entry.name);
    console.log("Type", entry.type);
    console.log("Size:", entry.size);
  });
});

The example above will print the name, type and size for every entry in the listing. A parsed line becomes a JavaScript object like this:

  {
    type: 1,
    size: 4096,
    name: "project2",
    time: 1382192220000,
    owner: "1001",
    group: "1001",

    userPermissions: {
      read: true,
      write: true,
      exec: true
    },

    groupPermissions: {
      read: false,
      write: false,
      exec: false
    },

    otherPermissions: {
      read: false,
      write: false,
      exec: false
    }
  }

Methods

parseEntries(string | array, callback)

Asynchronously parses a list of entries either in a single string (entries will be split by newlines) or in an array of strings. Invokes the callback when all the entries have been processed, and passes an array of JavaScript objects.

parseEntry(string)

Parses a single string such as:

drwxrwxrwx 2 1001 1001 4096 Sep 21 11:20 project

and returns the JavaScript object for it. There is no need to specify whether the entry is in UNIX or MS-DOS/Windows format. The parser will find out by itself.

Installation

With NPM:

npm install parse-listing

From GitHub:

git clone https://github.com/sergi/parse-listing.git

License

The MIT License

Copyright(c) 2013 Sergi Mansilla <sergi.mansilla AT gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

parse-listing's People

Contributors

sergi avatar v-braun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

parse-listing's Issues

Error in parser.js

Line 108, call to next() should be in:

process.nextTick(function()
{
next();
});

or call stack error is sometimes reached

Error on files with accent (like é)

Hello,
The decoding of filenames with accents returns '\charcode' with many modules (grunt-ftpsync) using parse-listing. Please, could you take a look at utf8 module to decode filenames with accents?
Example :
else if (parsedEntry) {
parsedEntry.name = utf8.decode(parsedEntry.name); // <<< code to add + require(‘utf8’) on top of parser.js file
parsed.push(parsedEntry);
}
Just a proposal, don't hesitate...
Regards,
JMZ

File stat error with ftp-srv

Hi,

I'm using ftp-srv as a server and jsftp as a client in my tests and I saw my test using JSFTP.ls() returned no entry when calling it on a file.

After inspection I find out ftp-srv is outputing:

212 -rw-rw-rw- 1 1 1        16190 Dec 07 16:25

which is remove because it does not match RE_MULTI in parser.js, because of the space between the code and the first -.

Is the solution to change RE_MULTI to /^(\d\d\d)\s?-/ to allow space or did I miss something?

I can make a PR if you think this is a bug. Thank you

After installing package useless files appeared!

Here is same problem:
npm install parse-listing

What's this:

..gitignore.un~                             │  1841
..travis.yml.un~                            │  2243
.Makefile.un~                               │ 38763
.package.json.un~                           │  1009
.parser.js.un~                              │   970
.parset_test.js.un~                         │ 17400
.README.md.un~                              │  6885

?

It must be removed from package.

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.