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

g11n-pipeline-flatten

v2.0.1

Published

Un/Flattener for jsonpath

Downloads

5,425

Readme

Un/Flattener for jsonpath

Experimental adjunct to the Globalization Pipeline Node.js SDK.

npm version Build Status Coverage Status

Purpose

The purpose of this utility is to flatten key/value pairs so that all keys and values are strings. Some types are ignored, such as empty right hand side values.

Also simple keys and values are by default left alone, so {key: "value"}=flatten({key:"value"}). The flattenAll: true option will include these keys in the flattening.

News

In version 2.x, single quotes are used. This conforms with the Java client as well as jsonpath standards. See https://github.com/IBM-Cloud/gp-js-flatten/issues/18

Usage

Given input=:

and

const flatten = require('g11n-pipeline-flatten');
const flat = flatten.flatten(input);

gives

and then

const expand = flatten.expand(flat);

gives

Using with the Globalization Pipeline

The flattener allows you to use deeply nested JSON structures with the Globalization Pipeline Node.js SDK, which service otherwise only supports flat key/value pairs.

See ./sample/SAMPLE-README.md for a full tutorial. The below gives a simple quickstart.

For example, you can “flatten” a JSON object before uploading to the Globalization Pipeline.

const flattener = require('g11n-pipeline-flatten')
var gpClient = require('g11n-pipeline').getClient(…);
gpClient.bundle('mybundle').uploadStrings({
    languageId: 'en',
    strings: flattener.flatten(require('./en.json'));
}, …);

Conversely, you can then “expand” the results when downloading from it.

const flattener = require('g11n-pipeline-flatten')
var gpClient = require('g11n-pipeline').getClient(…);
gpClient.bundle('mybundle').getStrings({
    languageId: 'en',
}, (err, result) => {
    …
    const expanded = flattener.expand(result.resourceStrings);
    // “expanded” is now the nested structure
});

API reference

Functions

flatten(obj, [opts])

Flatten a deeply nested object into its jsonpath equivalent

Kind: global function

| Param | Type | Default | Description | | --- | --- | --- | --- | | obj | Object | | The input object | | [opts] | Object | | Optional input parameters | | [opts.flattenAll] | Boolean | false | If true, flatten all values, even simple top level keys. |

expand(flattened, [opts])

Expand a flattened object into its deep equivalent

Kind: global function

| Param | Type | Description | | --- | --- | --- | | flattened | Object.<string, string> | The flattened object | | [opts] | Object | Optional input parameters |

docs autogenerated via jsdoc2md

Contributing

See CONTRIBUTING.md.

License

Apache 2.0. See LICENSE.txt

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.