Skip to content

Commit e4bc80c

Browse files
committed
New API
1 parent 103084b commit e4bc80c

19 files changed

Lines changed: 781 additions & 377 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
1313

14-
# Dependency directories (remove the comment below to include it)
14+
# Dependency directories
1515
# vendor/
16+
.vscode/

.godocdown.md

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,111 @@
33

44
[![Go Report Card](https://goreportcard.com/badge/github.com/goloop/scs)](https://goreportcard.com/report/github.com/goloop/scs) [![License](https://img.shields.io/badge/license-BSD-blue)](https://github.com/goloop/scs/blob/master/LICENSE) [![License](https://img.shields.io/badge/godoc-YES-green)](https://godoc.org/github.com/goloop/scs)
55

6-
*Version: .VERSION*
6+
*Version: .ModuleVersion*
77

88

9+
# SCS
10+
911
{{.EmitSynopsis}}
1012

13+
## Installation
14+
15+
To install this module use `go get` as:
16+
17+
$ go get -u github.com/goloop/scs
18+
19+
## Quick Start
20+
21+
To use this module import it as: `github.com/goloop/scs`
22+
23+
### Conversion functions
24+
25+
Example:
26+
27+
```go
28+
package main
29+
30+
import "github.com/goloop/scs"
31+
32+
func main() {
33+
var s string
34+
35+
// Simple text
36+
s = "hello world"
37+
scs.StrToCamel(s) // helloWorld
38+
scs.StrToPascal(s) // HelloWorld
39+
scs.StrToSnake(s) // hello_world
40+
scs.StrToKebab(s) // hello-world
41+
42+
// Text with abbreviations
43+
s = "http to https"
44+
scs.StrToCamel(s) // httpToHTTPS
45+
scs.StrToPascal(s) // HTTPToHTTPS
46+
scs.StrToSnake(s) // http_to_https
47+
scs.StrToKebab(s) // http-to-https
48+
49+
// Converting
50+
s = "http to https"
51+
camel := scs.StrToCamel(s) // httpToHTTPS
52+
pascal, _ := scs.CamelToPascal(camel) // HTTPToHTTPS <nil>
53+
kebab, _ := scs.PascalToKebab(pascal) // http-to-https <nil>
54+
snake, _ := scs.KebabToSnake(kebab) // http_to_https <nil>
55+
56+
// Use strings.ToUpper(snake) for convert to UPPER_SNAKE_CASE.
57+
58+
scs.SnakeToPascal(snake) // HTTPToHTTPS <nil>
59+
scs.CamelToKebab(camel) // http-to-https <nil>
60+
61+
// Errors
62+
scs.CamelToSnake(kebab) // value http-to-https isn't camelCase style
63+
scs.PascalToCamel(camel) // value httpToHTTPS isn't PascalCase style
64+
65+
// Convert anything to anything correctly
66+
scs.ToCamel(snake) // httpToHTTPS
67+
scs.ToPascal(kebab) // HTTPToHTTPS
68+
scs.ToSnake(s) // http_to_https
69+
}
70+
```
71+
72+
### Style objects
73+
74+
A safer way. Since each object knows what type it is and knows
75+
which conversion rules to use. This removes the need to return
76+
a second parameter as err when converting styles.
77+
78+
Example:
79+
80+
```go
81+
package main
82+
83+
import "github.com/goloop/scs"
84+
85+
func main() {
86+
var s string
87+
88+
// Simple text
89+
s = "hello world"
90+
snake, _ := scs.New(scs.Snake) // scs.New(scs.Snake, s)
91+
92+
snake.Eat(s) // hello_world
93+
snake.Set(s).Value() // hello_world
94+
snake.IsCamel() // false
95+
snake.IsSnake() // true
96+
snake.Value() // hello_world
97+
98+
camel := snake.CopyToCamel()
99+
camel.IsSnake() // false
100+
camel.IsCamel() // true
101+
camel.Value() // helloWorld
102+
103+
// Text with abbreviations
104+
s = "http to https"
105+
pascal, _ := scs.New(scs.Pascal, s)
106+
pascal.Value() // HTTPToHTTPS
107+
108+
kebab := pascal.CopyToKebab()
109+
kebab.Value() // http-to-https
110+
}
111+
```
11112

12113
{{ .EmitUsage }}

.module

Lines changed: 0 additions & 3 deletions
This file was deleted.

LICENSE

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2020-2021, GoLoop.
1+
Copyright (c) 2022, GoLoop.
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without
@@ -8,10 +8,7 @@ modification, are permitted provided that the following conditions are met:
88
2. Redistributions in binary form must reproduce the above copyright
99
notice, this list of conditions and the following disclaimer in the
1010
documentation and/or other materials provided with the distribution.
11-
3. All advertising materials mentioning features or use of this software
12-
must display the following acknowledgement:
13-
This product includes software developed by the GoLoop.
14-
4. Neither the name of the GoLoop nor the
11+
3. Neither the name of the GoLoop nor the
1512
names of its contributors may be used to endorse or promote products
1613
derived from this software without specific prior written permission.
1714

Makefile

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,37 @@
11
# GOLOOP
22
#
33
# Load data about the package:
4-
# REPOSITORY_NAME
4+
# NAME
5+
# Name of the GoLang's module;
6+
# VERSION
7+
# Current version.
8+
# REPOSITORY
59
# The name of the repository where the package is stored,
610
# for example: github.com/goloop;
7-
# MODULE_NAME
8-
# Name of the GoLang's pakcage.
9-
#
10-
# The REPOSITORY_NAME and MODULE_NAME create a path to import the package
11-
# (save the source code in GOPATH as $GOPATH/src/REPOSITORY_NAME/MODULE_NAME)
12-
SRC_PATH:=$(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
13-
include $(SRC_PATH)/.module
14-
15-
ifndef MODULE_NAME
16-
$(error Add PAKCAGE_NAME in .module)
17-
endif
18-
19-
ifndef REPOSITORY_NAME
20-
$(error Add REPOSITORY_NAME in .module)
21-
endif
22-
11+
MODULE_NAME:=$(shell cat go.mod | grep module | awk '{split($$2,v,"/"); print v[3]}')
12+
MODULE_VERSION:=$(shell cat doc.go | grep "const version" | awk '{gsub(/"/, "", $$4); print $$4}')
13+
MODULE_MAJOR_VERSION:=$(shell cat doc.go | grep "const version" | awk '{gsub(/"/, "", $$4); print $$4}' | awk '{split($$0,r,"."); print r[1]}')
14+
REPOSITORY_NAME:=$(shell cat go.mod | grep module | awk '{split($$2,v,"/"); print v[1] "/" v[2]}')
15+
2316
# Help information.
2417
define MSG_HELP
25-
Go-package manager.
18+
Go-package's manager of
19+
${MODULE_NAME} v${MODULE_VERSION}
2620

2721
Commands:
2822
help
2923
Show this help information
30-
go.test
24+
test
3125
Run tests
32-
go.test.cover
26+
cover
3327
Check test coverage
34-
go.lint
35-
Check cod with GoLints
36-
37-
Requires `golangci-lint`, install as:
38-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0
3928
readme
4029
Create readme from the GoLang code
4130

4231
Requires `godocdown`, install as:
4332
go get github.com/robertkrimen/godocdown/godocdown
44-
git.commit
45-
Update readme, create commit and update tag from the .module file.
46-
47-
Usage as: make git.commit am="Commit message"
33+
tag
34+
Create git-tag with current version of package
4835
endef
4936

5037
# Constants.
@@ -54,35 +41,19 @@ REPOSITORY_PATH=${REPOSITORY_NAME}/${MODULE_NAME}
5441
all: help
5542
help:
5643
@echo "$$MSG_HELP"
57-
go.test:
58-
@go clean -testcache; go test ${REPOSITORY_PATH}
59-
go.test.cover:
44+
test:
45+
@go clean -testcache; \
46+
go test ${REPOSITORY_PATH}
47+
cover:
6048
@go test -cover ${REPOSITORY_PATH} && \
6149
go test -coverprofile=/tmp/coverage.out ${REPOSITORY_PATH} && \
6250
go tool cover -func=/tmp/coverage.out && \
6351
go tool cover -html=/tmp/coverage.out
64-
go.lint:
65-
ifeq (, $(shell which golangci-lint))
66-
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0
67-
endif
68-
golangci-lint run --no-config --issues-exit-code=0 --timeout=30m \
69-
--disable-all --enable=deadcode --enable=gocyclo --enable=golint \
70-
--enable=varcheck --enable=structcheck --enable=maligned \
71-
--enable=gosec --enable=megacheck --enable=ineffassign \
72-
--enable=interfacer --enable=unconvert \
73-
--enable=goconst #--enable=errcheck --enable=dupl
7452
readme:
7553
ifeq (, $(shell which godocdown))
7654
@go get github.com/robertkrimen/godocdown/godocdown
7755
endif
7856
@godocdown -plain=true -template=.godocdown.md ./ | \
79-
sed -e 's/\.VERSION/${VERSION}/g' > README.md
80-
git.commit: readme
81-
ifeq ($(am),)
82-
@echo "You must provide a message to commit as: make commit am='Commit message'"
83-
else
84-
@git add . && git commit -am "${am}" && \
85-
git tag v${VERSION} && \
86-
git push -u origin --all && \
87-
git push -u origin --tag
88-
endif
57+
sed -e 's/\.ModuleVersion/v${MODULE_VERSION}/g' > README.md
58+
tag:
59+
@bash -c 'read -p "Do you want to create v${MODULE_VERSION} tag [y/n]?: " yn; case $${yn} in "y") git tag "v${MODULE_VERSION}"; exit 0;; *) exit 0;; esac'

0 commit comments

Comments
 (0)