All Projects → longbridgeapp → autocorrect

longbridgeapp / autocorrect

Licence: MIT License
Automatically add whitespace between Chinese and half-width characters (alphabetical letters, numerical digits and symbols).

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to autocorrect

autocorrect
自动给中英文之间加入合理的空格并纠正专用名词大小写
Stars: ✭ 56 (+211.11%)
Mutual labels:  correct, autocorrect
prettier-eslint-atom
DEPRECATED IN FAVOR OF prettier-atom + ESLint integration
Stars: ✭ 64 (+255.56%)
Mutual labels:  formatter
AutoFormatInputWatcher
This repository contains input watcher for auto formatting digits in edit text
Stars: ✭ 15 (-16.67%)
Mutual labels:  formatter
intl-format
A wrapper library for PHP to format and internationalize values in messages like sprintf
Stars: ✭ 12 (-33.33%)
Mutual labels:  formatter
formatters
A javascript library for formatting and manipulating.
Stars: ✭ 14 (-22.22%)
Mutual labels:  formatter
vim-ormolu
Plugin for formatting Haskell source code
Stars: ✭ 35 (+94.44%)
Mutual labels:  formatter
yamlfmt
A simple opionated yaml formatter that keeps your comments!
Stars: ✭ 27 (+50%)
Mutual labels:  formatter
tox-ini-fmt
Formats your tox.ini files
Stars: ✭ 19 (+5.56%)
Mutual labels:  formatter
unify
Modifies strings to all use the same quote where possible
Stars: ✭ 69 (+283.33%)
Mutual labels:  formatter
Fmt.jl
Python-style format strings for Julia
Stars: ✭ 31 (+72.22%)
Mutual labels:  formatter
canonix
Experiment in Nix formatting
Stars: ✭ 18 (+0%)
Mutual labels:  formatter
react-numeric
A react component for formatted number form fields
Stars: ✭ 30 (+66.67%)
Mutual labels:  formatter
react-put
A flexible formatter and i18n interface for React.
Stars: ✭ 23 (+27.78%)
Mutual labels:  formatter
prettier-check
Check that all files match prettier code style.
Stars: ✭ 54 (+200%)
Mutual labels:  formatter
dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (-5.56%)
Mutual labels:  formatter
atom-perfectionist
Beautify CSS and SCSS
Stars: ✭ 19 (+5.56%)
Mutual labels:  formatter
yapf-online
google/yapf online demo
Stars: ✭ 23 (+27.78%)
Mutual labels:  formatter
lucene
Node.js lib to transform: lucene query → syntax tree → lucene query
Stars: ✭ 61 (+238.89%)
Mutual labels:  formatter
StyLua
An opinionated Lua code formatter
Stars: ✭ 479 (+2561.11%)
Mutual labels:  formatter
teks
Easily get custom go template based outputs to your command-line tool. Like in docker/kubernetes
Stars: ✭ 41 (+127.78%)
Mutual labels:  formatter

AutoCorrrect for Go

Go

Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-width characters (alphabetical letters, numerical digits and symbols).

Go 版本的 AutoCorrect 实现,用于帮助开发者在 Go 的项目中使用自动纠正(提交内容或返回数据格式化)中英文之间空格,错误使用半角标点符号等问题,以确保产品能有统一的输出文案。

可配套采用 Rust 开发的 AutoCorrect 的 Lint、VS Code 以及 CI 检查流程等功能,来改进 I18n、项目文案、注释等细节。

Other implements

Features

  • Auto add spacings between CJK (Chinese, Japanese, Korean) and English words.
  • HTML content support.
  • Fullwidth -> halfwidth (only for [a-zA-Z0-9], and in time).
  • Correct punctuations into Fullwidth near the CJK.
  • Cleanup spacings.
  • Support options for custom format, unformat.

Usage

go get github.com/longbridgeapp/autocorrect

Use autocorrect.Format to format plain text.

https://play.golang.org/p/ntVhrGYnxNk

package main

import "github.com/longbridgeapp/autocorrect"

func main() {
  autocorrect.Format("长桥LongBridge App下载")
  // => "长桥 LongBridge App 下载"

  autocorrect.Format("Ruby 2.7版本第1次发布")
  // => "Ruby 2.7 版本第 1 次发布"

  autocorrect.Format("于3月10日开始")
  // => "于 3 月 10 日开始"

  autocorrect.Format("包装日期为2013年3月10日")
  // => "包装日期为 2013 年 3 月 10 日"

  autocorrect.Format("生产环境中使用Go")
  # => "生产环境中使用 Go"

  autocorrect.Format("本番環境でGoを使用する")
  # => "本番環境で Go を使用する"

  autocorrect.Format("프로덕션환경에서Go사용")
  # => "프로덕션환경에서 Go 사용"

  autocorrect.Format("需要符号?自动转换全角字符、数字:我们将在16:32分出发去CBD中心.")
  # => "需要符号?自动转换全角字符、数字:我们将在 16:32 分出发去 CBD 中心。"
}

With custom formatter:

type myFormatter struct {}
func (my myFormatter) Format(text string) string {
  return strings.ReplaceAll(text, "ios", "iOS")
}

autocorrect.Format("新版本ios即将发布", myFormatter{})
// "新版本 iOS 即将发布"
autocorrect.FormatHTML("<p>新版本ios即将发布</p>", myFormatter{})
// "<p>新版本 iOS 即将发布</p>"

Use autocorrect.Unformat to cleanup spacings in plain text.

package main

import "github.com/longbridgeapp/autocorrect"

func main() {
  autocorrect.Unformat("据港交所最新权益披露资料显示,2019 年 12 月 27 日,三生制药获 JP Morgan Chase & Co.每股均价 9.582 港元,增持 270.3 万股,总价约 2590 万港元。")
  // => "据港交所最新权益披露资料显示,2019年12月27日,三生制药获JP Morgan Chase & Co.每股均价9.582港元,增持270.3万股,总价约2590万港元。"
}

Use autocorrect.FormatHTML / autocorrect.UnformatHTML for HTML contents.

https://play.golang.org/p/pbETBF4OOcj

package main

import "github.com/longbridgeapp/autocorrect"

func main() {
  autocorrect.FormatHTML(htmlBody)
  // => "<div><p>长桥 LongBridge App 下载</p><p>最新版本 1.0</p></div>"
  autocorrect.UnformatHTML(htmlBody)
  // => "<div><p>长桥LongBridge App下载</p><p>最新版本1.0</p></div>"
}

Benchmark

Run go test -bench=. to benchmark.

pkg: github.com/longbridgeapp/autocorrect
BenchmarkFormat50-12      	   19671	     60175 ns/op
BenchmarkFormat100-12     	   10000	    119076 ns/op
BenchmarkFormat400-12     	    2847	    424984 ns/op
Benchmark_halfwidth-12    	  289411	      4150 ns/op
BenchmarkFormatHTML-12    	    1100	   1097027 ns/op

Format

Total chars Duration
50 0.06 ms
100 0.11 ms
400 0.42 ms

FormatHTML

Total chars Duration
2K 1.09 ms

License

This project under MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].