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

xml-locales

v1.0.0

Published

Tool for locales in xml files

Downloads

32

Readme

xml-locales

NPM

This is core package to work with localization files in xml.

Installation

npm install xml-locales
yarn add xml-locales
pnpm add xml-locales

[!IMPORTANT] This package, which works with XML files, has one root node named resources. This root node has child nodes named string. For example:

<resources>
  <string name="key1">value1</string>
  <string name="key2">value2</string>
</resources> 

Properties

| Args | Type | Required | Description | |------|------|----------|-------------| | xmlData | string | Buffer | XmlJsonData | false | Data of the xml document | | xmlOptions | object | false | It represents the options for the XML parser.

xmlOptions

The xmlOptions is used to customize the behavior of the XML parser and builder in the XmlLocales class.

| Prop | Type | Required | Description | |------|------|----------|-------------| | parserOptions | X2jOptionsOptional | false | Options to customize how the XML data is parsed. See below for details. For more information, see here | | builderOptions| XmlBuilderOptionsOptional | false | Options to customize how the XML data is built. See below for details. For more information, see here | | formateOptions| XMLFormatterOptions | false | Options to customize the formatting of the XML data. See below for details. For more information, see here |

Default Parser Options (X2jOptionsOptional)

| Option | Value | |-----------------------|--------| | trimValues | false | | ignoreDeclaration | true | | attributeNamePrefix | 'key_' | | alwaysCreateTextNode| true | | ignoreAttributes | false |

Default Builder Options (XmlBuilderOptionsOptional)

| Option | Value | |-----------------------|--------| | ignoreAttributes | false | | attributeNamePrefix | 'key_' | | processEntities | false |

Default Formatter Options (XMLFormatterOptions)

| Option | Value | |------------------|--------| | collapseContent| true | | indentation | ' ' |

Usage

import {XmlLocales} from 'xml-locales'

const xmlData = `
<resources>
  <string name="key1">value1</string>
  <string name="key2">value2</string>
</resources>
`

const xmlLocales = new XmlLocales(xmlData)
const jsonData = xmlLocales.add({keys: ['newKey'], values: ['newValue']}).toXML()

console.log(jsonData)

Output:

<resources>
   <string name="key1">value1</string>
   <string name="key2">value2</string>
   <string name="newKey">newValue</string>
</resources>

Update key/value

import {XmlLocales} from 'xml-locales'

const xmlData = `
<resources>
  <string name="key1">value1</string>
  <string name="key2">value2</string>
</resources>
`

const xmlLocales = new XmlLocales(xmlData)
const jsonData = xmlLocales.add({keys: ['newKey'], values: ['newValue']})
.update({oldValues: ['key1'], newValues: ['firstKey']})
.update({oldValues: ['value2'], newValues: ['secondValue']})
.toXML()

console.log(jsonData)

Output:

<resources>
   <string name="firstKey">value1</string>
   <string name="key2">secondValue</string>
</resources>

Delete by key/value

import {XmlLocales} from 'xml-locales'

const xmlData = `
<resources>
  <string name="key1">value1</string>
  <string name="key2">value2</string>
</resources>
`

const xmlLocales = new XmlLocales(xmlData)
const jsonData = xmlLocales.add({keys: ['newKey'], values: ['newValue']})
.deleteByKey('key1')
.deleteByValue('value2')
.toXML()

console.log(jsonData)

Output:

<resources>
</resources>

XML and JSON

import {XmlLocales} from 'xml-locales'

const xmlData = `
<resources>
  <string name="key1">value1</string>
  <string name="key2">value2</string>
</resources>
`

const xmlLocales = new XmlLocales(xmlData)
const xmlString = xmlLocales.toXML()
const jsonXml = xmlLocales.toJSON()

console.log(xmlString) // output XML
console.log(jsonXml) // output JSON

Output XML:

<resources>
  <string name="newKey2">newValue2</string>
  <string name="newKey">newValue</string>
  <string name="key2">value2</string>
  <string name="firstKey">value1</string>
</resources>

Output JSON:

{
 "resources": {
  "string": [
   {
    "key_name": "key1",
    "#text": "value1"
   },
   {
    "key_name": "key2",
    "#text": "value2"
   }
  ]
 }
}

Chaining

import {XmlLocales} from 'xml-locales'

const xmlData = `
<resources>
  <string name="key1">value1</string>
  <string name="key2">value2</string>
</resources>
`

const xmlLocales = new XmlLocales(xmlData)

const jsonData = xmlLocales.add({keys: ['newKey'], values: ['newValue']})
.add({keys: ['newKey2'], values: ['newValue2']})
.update({oldValues: ['key1'], newValues: ['firstKey']})
.sort('desc')
.toXML()

console.log(jsonData)

Output:

<resources>
  <string name="newKey2">newValue2</string>
  <string name="newKey">newValue</string>
  <string name="key2">value2</string>
  <string name="firstKey">value1</string>
</resources>

Packages

| Package | version | | ------- | -------- | | 📦xml-locales | NPM | | 💻@xml-locales/cli | NPM |