npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

resx-parser

v1.0.1

Published

A simple parser to parse resource files (.resx) to json for NodeJS

Downloads

427

Readme

resx-parser Build Status

A simple parser to parse resource files (.resx) to json for NodeJS.

It parses a .resx file or a resource encoded xml string or and returns a json object in the format { "resource_id" : resource value }. The 'shape' of generated json can be changed by using various options.All parsing is `async'.

It is written in ES6 and transpiled to ES5 using Babel .

Installation

npm install resx-parser --save

Usage

Parse a string

var ResxParser = require('resx-parser');
var xmlString =
  '<root>' +
  '<data name="Arm-Button" xml:space="preserve">' +
  '<value>Arm</value>' +
  '</data>' +
  '<data name="CoordinatesLabel" xml:space="preserve">' +
  '<value>Enter coordinates</value>' +
  '</data>' +
  '<data name="launchButton" xml:space="preserve">' +
  '<value>Launch</value>' +
  '</data>' +
  '<data name="title" xml:space="preserve">' +
  '<value>nuke launch controls</value>' +
  '</data>' +
  '</root>';

// init parser with default options
var parser = new ResxParser();

parser.parseString(xmlString, function(err, result) {
  if (err) {
    return console.log(err);
  } else {
    console.log(result);
  }
});

Parse a .resx file

var ResxParser = require('resx-parser');
  // init parser with default options
var parser = new ResxParser();
.parseResxFile("./example.resx", function(err, result) {
  if (err) {
    return console.log(err);
  } else {
    console.log(result);
  }
});

Options

resx-parser takes in an options object that controls the behaviour of parsing. The options object can have the following parameters.

convertIdCase

Use it convert the case of the resource id. By default it is 'camel'. This library uses change-case internally. The supported values are as follows.(description shamelessly stolen from change-case)

  • camel
    Converts to a string with the separators denoted by having the next letter capitalized.
    'test string' will be converted to "testString"

  • constant
    Converts to an upper case, underscore separated string.
    'test string' will be converted to "TEST_STRING"

  • dot
    Converts to a lower case, period separated string.
    'test string' will be converted to "test.string"

  • header
    Converts to a title cased, dash separated string.
    'test string' will be converted to "Test-String"

  • lower
    Return the string in lower case.
    'TEST STRING' will be converted to "test string"

  • lcFirst
    Return the string with the first character lower cased.
    'TEST' will be converted to "tEST"

  • no
    Return the string without any casing (lower case, space separated).
    'test string' will be converted to "test string"

  • param
    Converts to a lower case, dash separated string.
    'test string' will be converted to "test-string"

  • pascal
    Converts to a string denoted in the same fashion as camelCase, but with the first letter also capitalized.
    'test string' will be converted to "TestString"

  • path
    Converts to a lower case, slash separated string.
    'test string' will be converted to "test/string"

  • sentence
    Converts to a lower case, space separated string with the first letter upper case.
    'testString' will be converted to "Test string"

  • snake
    Converts to a lower case, underscore separated string.
    'test string' will be converted to "test_string"

  • swap
    Converts to a string with every character case reversed.
    'Test String' will be converted to "tEST sTRING"

  • title
    Converts to a space separated string with the first character of every word upper cased.
    'a simple test' will be converted to "A Simple Test"

  • upper
    Return the string in upper case.
    'test string' will be converted to "TEST STRING"

  • ucFirst
    Return the string with the first character upper cased. test' will be converted to "Test"

  var options = {
      convertIdCase: 'snake'
    };  

    var parser = new ResxParser(options);

fnTransformId

Use it to do any kind of processing on the resource id.

  var options = {
      fnTransformId: function(id) {
        return "RESOURCE_" + id;
      }
    };  

    var parser = new ResxParser(options);

fnTransformValue

Use it to do any kind of processing on the resource string or to change the stracture of the returned json object.

  var options = {
      fnTransformValue: function (id, value, comment) { 
        return {
          value:value,
          comment:comment
        };
      }
    };  

    var parser = new ResxParser(options);

this example would return

{
  foo:{
    value:"bar"
    comment:"label for foo button"
  }
}

filter

.Use it to filter out any resources from being processed.A return value of `true' will exclude the resource from processing.

  var options = {
      filter: function(id, value, comment) {
        return (id.lastIndexOf("_js_", 0) !== 0); // filters out all resources that does not start with _js_
      }  
    };

    var parser = new ResxParser(options);

Run Code Sample

npm run example

Tests

npm run test

Release History

  • 2016-06-19 1.0.0 Initial release

License

MIT license; see LICENSE.

(c) 2016 by Jayasanker Karakulath