dart_normalizer 0.9.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 2

dart_normalizer

Dart port of normalizr library https://github.com/paularmstrong/normalizr

Normalizr is a small, but powerful utility for taking JSON with a schema definition and returning nested entities with their IDs, gathered in dictionaries.

Quick Start

Consider a typical blog post. The API response for a single post might look something like this:

{
  "id": "123",
  "author": {
    "id": "1",
    "name": "Paul"
  },
  "title": "My awesome blog post",
  "comments": [
    {
      "id": "324",
      "commenter": {
        "id": "2",
        "name": "Nicole"
      }
    }
  ]
}

We have two nested entity types within our article: users and comments. Using various schema, we can normalize all three entity types down:

import 'dart:convert';
import 'package:dart_normalizer/normolizer.dart';
import 'package:dart_normalizer/schema/entity.dart';

// Define a users schema
final user = new EntitySchema('users');

// Define your comments schema
final comment = new EntitySchema('comments', {
  'commenter': user
});

// Define your article 
final article = new EntitySchema('articles', { 
  'author': user,
  'comments': [ comment ]
});

// convert json string to Map
var inputMap = JSON.decode(jsonString)
Map normalizedData = normalize(originalData, article);

Now, normalizedData will be:

{
  result: "123",
  entities: {
    "articles": { 
      "123": { 
        id: "123",
        author: "1",
        title: "My awesome blog post",
        comments: [ "324" ]
      }
    },
    "users": {
      "1": { "id": "1", "name": "Paul" },
      "2": { "id": "2", "name": "Nicole" }
    },
    "comments": {
      "324": { id: "324", "commenter": "2" }
    }
  }
}

Dependencies

None.

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dart_normalizer: ^0.9.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dart_normalizer/normolizer.dart';
import 'package:dart_normalizer/schema/array.dart';
import 'package:dart_normalizer/schema/entity.dart';
import 'package:dart_normalizer/schema/immutable_utils.dart';
import 'package:dart_normalizer/schema/object.dart';
import 'package:dart_normalizer/schema/polymorfic.dart';
import 'package:dart_normalizer/schema/schema.dart';
import 'package:dart_normalizer/schema/union.dart';
import 'package:dart_normalizer/schema/utils.dart';
import 'package:dart_normalizer/schema/value.dart';
  
Version Uploaded Documentation Archive
0.9.1 Mar 29, 2018 Go to the documentation of dart_normalizer 0.9.1 Download dart_normalizer 0.9.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
4
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
2
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Maintenance issues and suggestions

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0 <2.0.0