dart_normalizer 0.9.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 59

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 Flutter:


$ flutter packages get

Alternatively, your editor might support 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

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3
  • Flutter: 0.5.4

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
27 / 100
Health:
Code health derived from static analysis. [more]
94 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90 / 100
Overall score:
Weighted score of the above. [more]
59
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • Running dartdoc failed.

    Make sure dartdoc runs without any issues.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 19 hints.

    Run flutter format to format lib/normolizer.dart.

    Run flutter format to format lib/schema/array.dart.

    Similar analysis of the following files failed:

    • lib/schema/entity.dart (hint)
    • lib/schema/immutable_utils.dart (hint)
    • lib/schema/object.dart (hint)
    • lib/schema/polymorfic.dart (hint)
    • lib/schema/schema.dart (hint)
    • lib/schema/union.dart (hint)
    • lib/schema/utils.dart (hint)
    • lib/schema/value.dart (hint)
  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use dart_normalizer.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0 <2.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.10
meta 1.1.5
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6 2.0.7
Dev dependencies
flutter_test
test ^0.12.0