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 tracker.

tracker:

Libraries

humps
A Dart library for converting case style on strings and maps.