humps 1.0.3 copy "humps: ^1.0.3" to clipboard
humps: ^1.0.3 copied to clipboard

A Dart package for converting map keys between camelCase and snake_case. Useful for converting between JSON and Dart field names.

Humps #

A Dart package for converting string cases.

pub package Build Status codecov License: MIT GitHub stars GitHub forks

Installation #

Add humps to your pubspec.yaml file:

dependencies:
  humps: ^1.0.2

Usage #

On String #

import 'package:humps/humps.dart';

void main() {
  String camelCase = 'hello_world'.camelize(); 
  // Output: helloWorld
  String pascalCase = 'hello_world'.pascalize();
  // Output: HelloWorld
  String snakeCase = 'helloWorld'.decamelize();
  // Output: hello_world
  String kebabCase = 'helloWorld'.decamelize(separator: '-');
  // Output: hello-world
}

On Map #

import 'package:humps/humps.dart';

void main() {
  Map<String, dynamic> map = {
    'hello_world': 'Hello World',
    'helloWorld': 'Hello World',
  };

  Map<String, dynamic> camelizedMap = map.camelizeKeys();
  // Output: {helloWorld: Hello World, helloWorld: Hello World}
  Map<String, dynamic> pascalizedMap = map.pascalizeKeys();
  // Output: {HelloWorld: Hello World, HelloWorld: Hello World}
  Map<String, dynamic> snakeizedMap = map.decamelizeKeys();
  // Output: {hello_world: Hello World, hello_world: Hello World}
  Map<String, dynamic> kebabizedMap = map.decamelizeKeys(separator: '-');
  // Output: {hello-world: Hello World, hello-world: Hello World}
}

Features and bugs #

Please file feature requests and bugs at the [issue tracker][tracker].

[tracker]:

4
likes
150
points
59
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package for converting map keys between camelCase and snake_case. Useful for converting between JSON and Dart field names.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on humps