Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hughsk/flat
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.0.2
Choose a base ref
...
head repository: hughsk/flat
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.0.0
Choose a head ref

Commits on Aug 6, 2020

  1. Copy the full SHA
    e2a4443 View commit details
  2. Copy the full SHA
    90f7397 View commit details

Commits on Aug 18, 2022

  1. Copy the full SHA
    ae6a750 View commit details
  2. Copy the full SHA
    42aadd7 View commit details
  3. Copy the full SHA
    9627f63 View commit details
  4. Copy the full SHA
    fb33138 View commit details
  5. Bump mocha from 8.1.3 to 10.0.0

    Bumps [mocha](https://github.com/mochajs/mocha) from 8.1.3 to 10.0.0.
    - [Release notes](https://github.com/mochajs/mocha/releases)
    - [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
    - [Commits](mochajs/mocha@v8.1.3...v10.0.0)
    
    ---
    updated-dependencies:
    - dependency-name: mocha
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and jonkoops committed Aug 18, 2022
    Copy the full SHA
    eec36d8 View commit details
  6. Copy the full SHA
    bc553d7 View commit details
  7. Bump standard from 14.3.4 to 17.0.0

    Bumps [standard](https://github.com/standard/standard) from 14.3.4 to 17.0.0.
    - [Release notes](https://github.com/standard/standard/releases)
    - [Changelog](https://github.com/standard/standard/blob/master/CHANGELOG.md)
    - [Commits](standard/standard@v14.3.4...v17.0.0)
    
    ---
    updated-dependencies:
    - dependency-name: standard
      dependency-type: direct:development
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and jonkoops committed Aug 18, 2022
    Copy the full SHA
    230fae6 View commit details
  8. Copy the full SHA
    80707f6 View commit details

Commits on Aug 26, 2022

  1. Copy the full SHA
    a44236f View commit details
  2. Copy the full SHA
    addcb8b View commit details
  3. Copy the full SHA
    af99b27 View commit details

Commits on Sep 20, 2022

  1. Copy the full SHA
    8401156 View commit details
  2. Copy the full SHA
    0a20ce3 View commit details
  3. 6.0.0

    jonkoops committed Sep 20, 2022
    Copy the full SHA
    95b2a9f View commit details

Commits on Oct 17, 2022

  1. Bump mocha from 10.0.0 to 10.1.0 (#157)

    Bumps [mocha](https://github.com/mochajs/mocha) from 10.0.0 to 10.1.0.
    - [Release notes](https://github.com/mochajs/mocha/releases)
    - [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
    - [Commits](mochajs/mocha@v10.0.0...v10.1.0)
    
    ---
    updated-dependencies:
    - dependency-name: mocha
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Oct 17, 2022
    Copy the full SHA
    9049b52 View commit details

Commits on Dec 12, 2022

  1. Bump mocha from 10.1.0 to 10.2.0 (#158)

    Bumps [mocha](https://github.com/mochajs/mocha) from 10.1.0 to 10.2.0.
    - [Release notes](https://github.com/mochajs/mocha/releases)
    - [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
    - [Commits](mochajs/mocha@v10.1.0...v10.2.0)
    
    ---
    updated-dependencies:
    - dependency-name: mocha
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Dec 12, 2022
    Copy the full SHA
    ac4e903 View commit details

Commits on Jan 18, 2023

  1. Bump json5 from 1.0.1 to 1.0.2 (#159)

    Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
    - [Release notes](https://github.com/json5/json5/releases)
    - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
    - [Commits](json5/json5@v1.0.1...v1.0.2)
    
    ---
    updated-dependencies:
    - dependency-name: json5
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jan 18, 2023
    Copy the full SHA
    7a184e7 View commit details

Commits on Jun 5, 2023

  1. Bump standard from 17.0.0 to 17.1.0 (#163)

    Bumps [standard](https://github.com/standard/standard) from 17.0.0 to 17.1.0.
    - [Release notes](https://github.com/standard/standard/releases)
    - [Changelog](https://github.com/standard/standard/blob/master/CHANGELOG.md)
    - [Commits](standard/standard@v17.0.0...v17.1.0)
    
    ---
    updated-dependencies:
    - dependency-name: standard
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jun 5, 2023
    Copy the full SHA
    f69225d View commit details

Commits on Jul 19, 2023

  1. Bump word-wrap from 1.2.3 to 1.2.4 (#165)

    Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
    - [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
    - [Commits](jonschlinkert/word-wrap@1.2.3...1.2.4)
    
    ---
    updated-dependencies:
    - dependency-name: word-wrap
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jul 19, 2023
    Copy the full SHA
    a47295f View commit details

Commits on Sep 15, 2023

  1. Copy the full SHA
    ed9008e View commit details
  2. Copy the full SHA
    b83311d View commit details
  3. Copy the full SHA
    906cba6 View commit details
Showing with 4,964 additions and 1,735 deletions.
  1. +8 −0 .github/dependabot.yml
  2. +28 −0 .github/workflows/main.yml
  3. +0 −8 .travis.yml
  4. +8 −10 README.md
  5. +6 −8 cli.js
  6. +17 −0 index.d.ts
  7. +7 −8 index.js
  8. +4,842 −1,668 package-lock.json
  9. +26 −11 package.json
  10. +22 −22 test/test.js
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: npm
directory: /
open-pull-requests-limit: 999
rebase-strategy: disabled
schedule:
interval: weekly
28 changes: 28 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20]
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
check-latest: true
cache: npm

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# flat [![Build Status](https://secure.travis-ci.org/hughsk/flat.png?branch=master)](http://travis-ci.org/hughsk/flat)
# flat [![Build Status](https://github.com/hughsk/flat/actions/workflows/main.yml/badge.svg)](https://github.com/hughsk/flat/actions/workflows/main.yml)

Take a nested Javascript object and flatten it, or unflatten an object with
delimited keys.
@@ -17,7 +17,7 @@ Flattens the object - it'll return an object one level deep, regardless of how
nested the original object was:

``` javascript
var flatten = require('flat')
import { flatten } from 'flat'

flatten({
key1: {
@@ -38,10 +38,10 @@ flatten({

### unflatten(original, options)

Flattening is reversible too, you can call `flatten.unflatten()` on an object:
Flattening is reversible too, you can call `unflatten` on an object:

``` javascript
var unflatten = require('flat').unflatten
import { unflatten } from 'flat'

unflatten({
'three.levels.deep': 42,
@@ -72,7 +72,7 @@ When enabled, both `flat` and `unflatten` will preserve arrays and their
contents. This is disabled by default.

``` javascript
var flatten = require('flat')
import { flatten } from 'flat'

flatten({
this: [
@@ -140,7 +140,7 @@ This only makes sense on ordered arrays, and since we're overwriting data, shoul
Maximum number of nested objects to flatten.

``` javascript
var flatten = require('flat')
import { flatten } from 'flat'

flatten({
key1: {
@@ -164,8 +164,7 @@ flatten({
Transform each part of a flat key before and after flattening.

```javascript
var flatten = require('flat')
var unflatten = require('flat').unflatten
import { flatten, unflatten } from 'flat'

flatten({
key1: {
@@ -210,8 +209,7 @@ unflatten({

## Command Line Usage

`flat` is also available as a command line tool. You can run it with
[`npx`](https://ghub.io/npx):
`flat` is also available as a command line tool. You can run it with [`npx`](https://docs.npmjs.com/cli/v8/commands/npx):

```sh
npx flat foo.json
14 changes: 6 additions & 8 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')
const readline = require('readline')

const flat = require('./index')
import fs from 'node:fs'
import path from 'node:path'
import readline from 'node:readline'
import { flatten } from './index.js'

const filepath = process.argv.slice(2)[0]
if (filepath) {
// Read from file
const file = path.resolve(process.cwd(), filepath)
fs.accessSync(file, fs.constants.R_OK) // allow to throw if not readable
out(require(file))
out(JSON.parse(fs.readFileSync(file)))
} else if (process.stdin.isTTY) {
usage(0)
} else {
@@ -27,7 +25,7 @@ if (filepath) {
}

function out (data) {
process.stdout.write(JSON.stringify(flat(data), null, 2))
process.stdout.write(JSON.stringify(flatten(data), null, 2))
}

function usage (code) {
17 changes: 17 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface FlattenOptions {
delimiter?: string;
maxDepth?: number;
safe?: boolean;
transformKey?: (key: string) => string;
}

export function flatten<T, R>(target: T, options?: FlattenOptions): R;

export interface UnflattenOptions {
delimiter?: string;
object?: boolean;
overwrite?: boolean;
transformKey?: (key: string) => string;
}

export function unflatten<T, R>(target: T, options?: UnflattenOptions): R;
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module.exports = flatten
flatten.flatten = flatten
flatten.unflatten = unflatten

function isBuffer (obj) {
return obj &&
obj.constructor &&
@@ -13,7 +9,7 @@ function keyIdentity (key) {
return key
}

function flatten (target, opts) {
export function flatten (target, opts) {
opts = opts || {}

const delimiter = opts.delimiter || '.'
@@ -51,7 +47,7 @@ function flatten (target, opts) {
return output
}

function unflatten (target, opts) {
export function unflatten (target, opts) {
opts = opts || {}

const delimiter = opts.delimiter || '.'
@@ -73,7 +69,8 @@ function unflatten (target, opts) {
isNaN(parsedKey) ||
key.indexOf('.') !== -1 ||
opts.object
) ? key
)
? key
: parsedKey
}

@@ -139,7 +136,9 @@ function unflatten (target, opts) {
if ((overwrite && !isobject) || (!overwrite && recipient[key1] == null)) {
recipient[key1] = (
typeof key2 === 'number' &&
!opts.object ? [] : {}
!opts.object
? []
: {}
)
}

Loading