mirror of
https://github.com/jimeh/undent.git
synced 2026-02-19 11:56:39 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1148580df | ||
|
c3c5f71c7a
|
|||
|
2e276c037b
|
|||
| af31c21ec1 | |||
|
84715b90d0
|
|||
|
3878874bbe
|
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "1.1.1"
|
||||
".": "1.1.2"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## [1.1.2](https://github.com/jimeh/undent/compare/v1.1.1...v1.1.2) (2024-10-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **perf:** minor improvement when no indent is found ([84715b9](https://github.com/jimeh/undent/commit/84715b90d000292e4e4fbe081e00a583acf0dada))
|
||||
|
||||
## [1.1.1](https://github.com/jimeh/undent/compare/v1.1.0...v1.1.1) (2022-12-05)
|
||||
|
||||
|
||||
|
||||
30
README.md
30
README.md
@@ -9,29 +9,13 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://pkg.go.dev/github.com/jimeh/undent">
|
||||
<img src="https://img.shields.io/badge/%E2%80%8B-reference-387b97.svg?logo=go&logoColor=white"
|
||||
alt="Go Reference">
|
||||
</a>
|
||||
<a href="https://github.com/jimeh/undent/releases">
|
||||
<img src="https://img.shields.io/github/v/tag/jimeh/undent?label=release" alt="GitHub tag (latest SemVer)">
|
||||
</a>
|
||||
<a href="https://github.com/jimeh/undent/actions">
|
||||
<img src="https://img.shields.io/github/workflow/status/jimeh/undent/CI.svg?logo=github" alt="Actions Status">
|
||||
</a>
|
||||
<a href="https://codeclimate.com/github/jimeh/undent">
|
||||
<img src="https://img.shields.io/codeclimate/coverage/jimeh/undent.svg?logo=code%20climate" alt="Coverage">
|
||||
</a>
|
||||
<a href="https://github.com/jimeh/undent/issues">
|
||||
<img src="https://img.shields.io/github/issues-raw/jimeh/undent.svg?style=flat&logo=github&logoColor=white"
|
||||
alt="GitHub issues">
|
||||
</a>
|
||||
<a href="https://github.com/jimeh/undent/pulls">
|
||||
<img src="https://img.shields.io/github/issues-pr-raw/jimeh/undent.svg?style=flat&logo=github&logoColor=white" alt="GitHub pull requests">
|
||||
</a>
|
||||
<a href="https://github.com/jimeh/undent/blob/main/LICENSE">
|
||||
<img src="https://img.shields.io/github/license/jimeh/undent.svg?style=flat" alt="License Status">
|
||||
</a>
|
||||
<a href="https://pkg.go.dev/github.com/jimeh/undent"><img src="https://img.shields.io/badge/%E2%80%8B-reference-387b97.svg?logo=go&logoColor=white" alt="Go Reference"></a>
|
||||
<a href="https://github.com/jimeh/undent/releases"><img src="https://img.shields.io/github/v/tag/jimeh/undent?label=release" alt="GitHub tag (latest SemVer)"></a>
|
||||
<a href="https://github.com/jimeh/undent/actions"><img src="https://img.shields.io/github/actions/workflow/status/jimeh/undent/ci.yml?logo=github" alt="Actions Status"></a>
|
||||
<a href="https://codeclimate.com/github/jimeh/undent"><img src="https://img.shields.io/codeclimate/coverage/jimeh/undent.svg?logo=code%20climate" alt="Coverage"></a>
|
||||
<a href="https://github.com/jimeh/undent/issues"><img src="https://img.shields.io/github/issues-raw/jimeh/undent.svg?style=flat&logo=github&logoColor=white" alt="GitHub issues"></a>
|
||||
<a href="https://github.com/jimeh/undent/pulls"><img src="https://img.shields.io/github/issues-pr-raw/jimeh/undent.svg?style=flat&logo=github&logoColor=white" alt="GitHub pull requests"></a>
|
||||
<a href="https://github.com/jimeh/undent/blob/main/LICENSE"><img src="https://img.shields.io/github/license/jimeh/undent.svg?style=flat" alt="License Status"></a>
|
||||
</p>
|
||||
|
||||
```go
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
{
|
||||
"bootstrap-sha": "369ec87dddfae22534693f8cf3be6cb85bc46f9d",
|
||||
"last-release-sha": "369ec87dddfae22534693f8cf3be6cb85bc46f9d",
|
||||
"release-type": "go",
|
||||
"bump-minor-pre-major": true,
|
||||
"bump-patch-for-minor-pre-major": true,
|
||||
|
||||
10
undent.go
10
undent.go
@@ -22,7 +22,7 @@ func Bytes(s string) []byte {
|
||||
}
|
||||
|
||||
// find smallest indent relative to each line-feed
|
||||
min := 99999999999
|
||||
min := -1
|
||||
count := 0
|
||||
|
||||
lfs := make([]int, 0, strings.Count(s, "\n"))
|
||||
@@ -35,7 +35,7 @@ func Bytes(s string) []byte {
|
||||
if s[i] == lf {
|
||||
lfs = append(lfs, i)
|
||||
indent = 0
|
||||
} else if indent < min {
|
||||
} else if indent < min || min == -1 {
|
||||
switch s[i] {
|
||||
case spc, tab:
|
||||
indent++
|
||||
@@ -43,13 +43,17 @@ func Bytes(s string) []byte {
|
||||
if indent > 0 {
|
||||
count++
|
||||
}
|
||||
if indent < min {
|
||||
if indent < min || min == -1 {
|
||||
min = indent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if min == -1 {
|
||||
return []byte(s)
|
||||
}
|
||||
|
||||
// extract each line without indentation
|
||||
out := make([]byte, 0, len(s)-(min*count))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user