mno_commons 0.1.2 copy "mno_commons: ^0.1.2" to clipboard
mno_commons: ^0.1.2 copied to clipboard

This package provide utilities (JSON, io, Href, UriTemplate, etc...) for other mno_xxx packages.

example/lib/main.dart

// Copyright (c) 2021 Mantano. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:mno_commons/extensions/strings.dart';
import 'package:mno_commons/utils/jsonable.dart';

void main() {
  Map<String, dynamic> json = """{
            "a": 1,
            "b": { "b.1": "hello" },
            "c": [true, 42, "world"]
        }"""
      .toJsonOrNull()!;
  assert(json["a"] == 1);
  _Person person1 = _Person("Stewart", "Marion");
  json.putJSONableIfNotEmpty("person1", person1);
  print("person1: ${json["person1"]}");
  _Person person2 = _Person(null, null);
  json.putJSONableIfNotEmpty("person2", person2);
  assert(json["person2"] == null);
}

class _Person with JSONable {
  final String? name;
  final String? firstname;

  _Person(this.name, this.firstname);

  @override
  Map<String, dynamic>? toJson() => <String, dynamic>{}
    ..putOpt("name", name)
    ..putOpt("firstname", firstname);
}
0
likes
130
pub points
29%
popularity

Publisher

verified publishermantano.com

This package provide utilities (JSON, io, Href, UriTemplate, etc...) for other mno_xxx packages.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

archive, crypto, dartx, dfunc, fimber, meta, path, universal_io

More

Packages that depend on mno_commons