Package strnaming is used to Convert string to camelCase, snake_case, kebab-case.

strnaming

Godoc Reference Go Report Card Build Status  Release Goproxy.cn

Package strnaming is used to Convert string to camelCase, snake_case, kebab-case.

Contents

API Examples

Install

To start using strnaming, install Go and run go get:

$ go get -u github.com/startdusk/strnaming

This will retrieve the library.

Quick start

camel

package main

import (
	"fmt"

	"github.com/startdusk/strnaming"
)

func main() {
	// camel case
	camel := strnaming.NewCamel()
	fmt.Println(camel.Convert("camelcase_key")) // camelcaseKey

	fmt.Println(camel.Convert("user_id")) // userId

	camel.WithDelimiter('-')
	fmt.Println(camel.Convert("user-id")) // userId

	camel.WithUpperFirst(true)
	fmt.Println(camel.Convert("user_id")) // UserId

	camel.WithCache("user_id", "UserID")
	fmt.Println(camel.Convert("user_id")) // UserID

	fmt.Println(camel.Convert("json_data")) // JsonData
	fmt.Println(camel.Convert("http_test")) // HttpTest

	camel.WithPrefix("My")
	camel.WithUpperFirst(false)
	fmt.Println(camel.Convert("user_name")) // MyuserName
}
using golang style
package main

import (
	"fmt"

	"github.com/startdusk/strnaming"
	"github.com/startdusk/strnaming/style"
)

func main() {
	camel := strnaming.NewCamel()
	fmt.Println(camel.Convert("json_data")) // JsonData
	fmt.Println(camel.Convert("http_test")) // HttpTest
	
	camel.WithStyle(style.NewGolang())
	fmt.Println(camel.Convert("json_data")) // JSONData
	fmt.Println(camel.Convert("http_test")) // HTTPTest
}

snake

package main

import (
	"fmt"

	"github.com/startdusk/strnaming"
)

func main() {
	// snake case
	snake := strnaming.NewSnake()
	fmt.Println(snake.Convert("SnakeKey")) // snake_key

	snake.WithIgnore('-')
	fmt.Println(snake.Convert("My-IDCard")) // my-id_card

	snake.WithScreaming(true)
	fmt.Println(snake.Convert("SnakeKey")) // SNAKE_KEY

	snake.WithCache("UserID", "userid")
	fmt.Println(snake.Convert("UserID")) // userid

	snake.WithPrefix("go")
	snake.WithScreaming(false)
	fmt.Println(snake.Convert("PageSize")) // go_page_size
}

kebab

package main

import (
	"fmt"

	"github.com/startdusk/strnaming"
)

func main() {
	// kebab case
	kebab := strnaming.NewKebab()
	fmt.Println(kebab.Convert("KebabKey")) // kebab-key

	kebab.WithIgnore('@', '.')
	fmt.Println(kebab.Convert("[email protected]")) // [email protected]

	kebab.WithScreaming(true)
	fmt.Println(kebab.Convert("KebabKey")) // KEBAB-KEY

	kebab.WithCache("UserID", "User-Id")
	fmt.Println(kebab.Convert("UserID")) // User-Id

	kebab.WithPrefix("go")
	kebab.WithScreaming(false)
	fmt.Println(kebab.Convert("PageSize")) // go-page-size
}

CLI Examples

Install

To start using strnaming in command line, install Go and run go get:

$ go get -u github.com/startdusk/strnaming/cmd/strnaming

Quick start

convert json keys to camelcase keys, like:

// ./testdata/test.json

{
  "test_url": "http://json-schema.org/draft-04/schema",
  "another_case": [
    {
      "sub_case": [
        {
          "for_ready": 1234,
          "bba_media": "hahahaha"
        }
      ]
    },
    {
      "sub_url_two": [
        {
          "for_ready_two": "ben",
          "bba_media_two": 2021,
          "key_space": [
            [
              [
                {
                  "low_code": true
                }
              ]
            ]
          ]
        }
      ]
    }
  ]
}

command:

$ strnaming c -f=./testdata/test.json

output:

{
  "anotherCase": [
    {
      "subCase": [
        {
          "bbaMedia": "hahahaha",
          "forReady": 1234
        }
      ]
    },
    {
      "subUrlTwo": [
        {
          "bbaMediaTwo": 2021,
          "forReadyTwo": "ben",
          "keySpace": [
            [
              [
                {
                  "lowCode": true
                }
              ]
            ]
          ]
        }
      ]
    }
  ],
  "testUrl": "http://json-schema.org/draft-04/schema"
}

Help

using main command:

$ strnaming help

output:

NAME:
   strnaming - a cli tool to convert string name

USAGE:
   strnaming [global options] command [command options] [arguments...]

VERSION:
   v0.4.0 linux/amd64

COMMANDS:
   camel, c  convert to camel string
   snake, s  convert to snake string
   kebab, k  convert to kabab string
   help, h   Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help (default: false)
   --version, -v  print the version (default: false)

using sub command like camel:

$ strnaming c -help

output:

NAME:
   strnaming camel - convert to camel string

USAGE:
   strnaming camel [command options] [arguments...]

OPTIONS:
   --file value, -f value       input a json file path (eg: /path/to/strnaming.json)
   --json value, -j value       input a json
   --delimiter value, -d value  using custom delimiter (default: _)
   --upperFirst, --uf           using first char upper (default: false)
   --prefix value, -p value     using prefix
   --cache value, -c value      using cache (eg: -c="user_id" -c="UserID")
   --help, -h                   show help (default: false)

TODO

  • Add prefix for string
  • Cli for command line access
  • Support Golang language naming style
  • Support Golang language naming style for cli tool
Similar Resources

Convert Gitignore to Glob patterns in Go

globify-gitignore Convert Gitignore to Glob patterns A Go

Nov 8, 2021

A Go utility to convert Go example tests into jupyter notebooks.

go2colab Scientists (my main project's users) love jupyter notebook tutorials pkg.dev.go's runnable playground doesn't support file IO but I love exam

Jul 10, 2022

Convert dates from or to 31 calendars in Go. Implements the functions discussed in Reingold/Dershowitz 2018.

libcalcal - Calendrical calculations in Go About libcalcal implements in Go the functions described and presented in: Reingold, Edward M., and Nachum

Dec 30, 2021

A package for running subprocesses in Go, similar to Python's subprocesses package.

A package for running subprocesses in Go, similar to Python's subprocesses package.

Jul 28, 2022

Utility to restrict which package is allowed to import another package.

go-import-rules Utility to restrict which package is allowed to import another package. This tool will read import-rules.yaml or import-rules.yml in t

Jan 7, 2022

a decision & trigger framework backed by Google's Common Expression Language used in graphikDB

a decision & trigger framework backed by Google's Common Expression Language used in graphikDB

Nov 15, 2022

流媒体NetFlix解锁检测脚本 / A script used to determine whether your network can watch native Netflix movies or not

流媒体NetFlix解锁检测脚本 / A script used to determine whether your network can watch native Netflix movies or not

netflix-verify 流媒体NetFlix解锁检测脚本,使用Go语言编写 在VPS网络正常的情况下,哪怕是双栈网络也可在几秒内快速完成IPv4/IPv6的解锁判断 鸣谢 感谢 @CoiaPrant 指出对于地域检测更简便的方法 感谢 @XmJwit 解决了IPV6 Only VPS无法下载脚

Dec 29, 2022

This is an open source project for commonly used functions for the Go programming language.

Common Functions This is an open source project for commonly used functions for the Go programming language. This package need = go 1.3 Code Conventi

Jan 8, 2023

sigbypass4xx is a utility to automate well-know techniques used to bypass access control restrictions.

sigbypass4xx sigbypass4xx is a utility to automate well-know techniques used to bypass access control restrictions. Resources Usage Installation From

Nov 9, 2022
Cell is a Go package that creates new instances by string in running time.

Cell Cell is a Go package that creates new instances by string in running time. Getting Started Installing To start using CELL, install Go and run go

Dec 20, 2021
go-to64 analyzes Golang main package to convert int/uint to int64/uint64.

go-to64 About go-to64 analyzes Golang main package to convert int/uint to int64/uint64. This is an experiment tool, so be very careful. In a 32-bit en

Oct 31, 2021
Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.
Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.

Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al. This library is external dependency-free. It only depends on the Go standard library.

Dec 27, 2022
💪 Helper Utils For The Go: string, array/slice, map, format, cli, env, filesystem, test and more.
💪 Helper Utils For The Go: string, array/slice, map, format, cli, env, filesystem, test and more.

?? Helper Utils For The Go: string, array/slice, map, format, cli, env, filesystem, test and more. Go 的一些工具函数,格式化,特殊处理,常用信息获取等等

Jan 6, 2023
Deduplicated and GC-friendly string store

This library helps to store big number of strings in structure with small number of pointers to make it friendly to Go garbage collector.

Nov 10, 2021
ms - 'my story' creates a secure password string which can be memorized with a technique shared by Max.

On 23.12.21 20:22, Stefan Claas wrote: [...] > > Yes, I am aware of that, but how can one memorize a key when traveling > and not taking any devices

Dec 24, 2021
Q2entities - Parse the entities string from a Quake 2 .bsp map file. Written in Go

Q2Entities A simple command-line utility to extract the entities string from a Quake 2 map file. Entities? Binary Space Partitioning maps (.bsp) conta

Apr 9, 2022
Generates a random alphanumeric string of a given length.

randstring randstring.Create () is fast and has minimal memory allocation. It returns a random alphanumeric string of a given length. Install go get g

Jan 7, 2022
Convert Arabic numeric amounts to Chinese character

将阿拉伯数字金额转换为汉字的形式 Convert Arabic numeric amounts to Chinese character form. 安装使用 Golang 版本大于等于1.16 go get -u github.com/aliliin/rmb-character import (

Sep 9, 2021
krconv -- Convert kana-character to roman-alphabet
 krconv -- Convert kana-character to roman-alphabet

krconv -- Convert kana-character to roman-alphabet Convert kana-characters to roman-alphabets (by hepburn romanization) This package is required Go 1.

Aug 8, 2022