{"id":29574742,"url":"https://github.com/nao1215/stringx","last_synced_at":"2025-07-19T08:39:36.447Z","repository":{"id":301562055,"uuid":"1009378154","full_name":"nao1215/stringx","owner":"nao1215","description":"stringx - Unicode-aware string utilities in OCaml","archived":false,"fork":false,"pushed_at":"2025-07-02T13:59:20.000Z","size":794,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-17T03:54:52.911Z","etag":null,"topics":["algorithm","levenshtein-distance","ocaml","string"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nao1215.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"nao1215"}},"created_at":"2025-06-27T03:19:06.000Z","updated_at":"2025-07-04T03:14:08.000Z","dependencies_parsed_at":"2025-06-27T14:39:17.550Z","dependency_job_id":"e71c4112-b7d3-4a7a-ac2a-c7c8021e75bb","html_url":"https://github.com/nao1215/stringx","commit_stats":null,"previous_names":["nao1215/stringx"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nao1215/stringx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nao1215%2Fstringx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nao1215%2Fstringx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nao1215%2Fstringx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nao1215%2Fstringx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nao1215","download_url":"https://codeload.github.com/nao1215/stringx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nao1215%2Fstringx/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265905116,"owners_count":23846696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","levenshtein-distance","ocaml","string"],"created_at":"2025-07-19T08:39:35.806Z","updated_at":"2025-07-19T08:39:36.441Z","avatar_url":"https://github.com/nao1215.png","language":"OCaml","readme":"[![Build and Test](https://github.com/nao1215/stringx/actions/workflows/test.yml/badge.svg)](https://github.com/nao1215/stringx/actions/workflows/test.yml)\n[![Dependabot Updates](https://github.com/nao1215/stringx/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/nao1215/stringx/actions/workflows/dependabot/dependabot-updates)\n![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)\n![GitHub stars](https://img.shields.io/github/stars/nao1215/stringx?style=social)\n[![Documentation](https://img.shields.io/badge/docs-online-blue)](https://nao1215.github.io/stringx/)\n\n\n# Unicode-aware string utilities in OCaml\n\n**stringx** is a OCaml library that brings robust Unicode (UTF-8) support to your string processing tasks.\n\n\u003e [!NOTE]\n\u003e This project is inspired by [huandu/xstrings](https://github.com/huandu/xstrings).  \n\u003e\n\u003e The goal is to bring string manipulation features found in other programming languages to OCaml. **This library is under active development.**  \n\u003e Function proposals and contributions for new string utilities are very welcome! As I am new to OCaml, I welcome your feedback and suggestions 😊\n\nWith stringx, you get:\n- Accurate edit distance (Levenshtein) calculations for any language or emoji\n- Smart centering of strings, even with multibyte characters\n- Flexible character counting and deletion using intuitive patterns, ranges, and negation\n\n\n---\n\n## ✨ Features\n\n- **Unicode-first:** All functions are fully UTF-8 aware—works perfectly with emoji, Japanese, Chinese, and more!\n- **Flexible pattern matching:** Use character sets, ranges (e.g. `\"a-z\"` or `\"あ-ん\"`), and negation (`\"^0-9\"`) for powerful string operations.\n- **No C bindings:** Pure OCaml, easy to install and portable.\n- **Battle-tested:** Includes comprehensive tests for edge cases and malformed UTF-8.\n\n---\n\n## 🔧 API Overview\n\nThe latest API documentation is published at:  \n👉 [https://nao1215.github.io/stringx/stringx/Stringx/index.html](https://nao1215.github.io/stringx/stringx/Stringx/index.html)\n\n```ocaml\n(** Computes the Levenshtein distance between two UTF-8 strings. *)\nval distance : s:string -\u003e t:string -\u003e int\n\n(** Centers a string within a specified length, padding as needed. *)\nval center : len:int -\u003e pad:string -\u003e string -\u003e string\n\n(** Counts Unicode characters in a string that match a given pattern. *)\nval count : pattern:string -\u003e string -\u003e int\n\n(** Deletes Unicode characters from a string that match a given pattern. *)\nval delete : pattern:string -\u003e string -\u003e string\n\n(** Returns the number of Unicode code points in a string. *)\nval length : string -\u003e int\n\n(** Reverses a UTF-8 encoded string by Unicode code points. *)\nval reverse : string -\u003e string\n\n(** Checks if a string contains a specific substring. *)\nval contains : substr:string -\u003e string -\u003e bool\n\n(** Checks if a string contains any Unicode code points from a given set. *)\nval contains_any : chars:string -\u003e string -\u003e bool\n\n(** Checks if a string starts with a given prefix. *)\nval has_prefix : prefix:string -\u003e string -\u003e bool\n\n(** Checks if a string ends with a given suffix. *)\nval has_suffix : suffix:string -\u003e string -\u003e bool\n\n(** Counts non-overlapping occurrences of a substring. *)\nval count_substring : substr:string -\u003e string -\u003e int\n\n(** Compares two strings for equality, ignoring case (ASCII only). *)\nval equal_fold : other:string -\u003e string -\u003e bool\n\n(** Splits a string into a list of words, using whitespace as a delimiter. *)\nval fields : string -\u003e string list\n\n(** Splits a string using a custom delimiter function. *)\nval fields_func : f:(Uchar.t -\u003e bool) -\u003e string -\u003e string list\n\n(** Finds the first index of a substring. *)\nval index : substr:string -\u003e string -\u003e int\n\n(** Repeats a string a specified number of times. *)\nval repeat : count:int -\u003e string -\u003e string\n\n(** Joins a list of strings into a single string with a separator. *)\nval join : sep:string -\u003e string list -\u003e string\n\n(** Removes leading and trailing characters from a string that are in a given set. *)\nval trim : cutset:string -\u003e string -\u003e string\n\n(** Removes leading and trailing characters from a string based on a predicate. *)\nval trim_func : f:(Uchar.t -\u003e bool) -\u003e string -\u003e string\n\n(** Removes leading characters from a string that are in a given set. *)\nval trim_left : cutset:string -\u003e string -\u003e string\n\n(** Removes leading characters from a string based on a predicate. *)\nval trim_left_func : f:(Uchar.t -\u003e bool) -\u003e string -\u003e string\n\n(** Removes trailing characters from a string that are in a given set. *)\nval trim_right : cutset:string -\u003e string -\u003e string\n\n(** Removes trailing characters from a string based on a predicate. *)\nval trim_right_func : f:(Uchar.t -\u003e bool) -\u003e string -\u003e string\n\n(** Removes leading and trailing whitespace from a string. *)\nval trim_space : string -\u003e string\n\n(** Removes a trailing suffix from a string. *)\nval trim_suffix : suffix:string -\u003e string -\u003e string\n\n(** Converts a string to lowercase. *)\nval to_lower : string -\u003e string\n\n(** Converts a string to title case. *)\nval to_title : string -\u003e string\n\n(** Converts a string to uppercase. *)\nval to_upper : string -\u003e string\n\n(** Converts a string to camelCase. *)\nval to_camel_case : string -\u003e string\n\n(** Converts a string to kebab-case. *)\nval to_kebab_case : string -\u003e string\n\n(** Converts a string to PascalCase. *)\nval to_pascal_case : string -\u003e string\n\n(** Converts a string to snake_case. *)\nval to_snake_case : string -\u003e string\n\n(** Applies a function to each Unicode code point in a string. *)\nval map : f:(Uchar.t -\u003e Uchar.t) -\u003e string -\u003e string\n\n(** Maps and filters Unicode code points in a string. *)\nval filter_map : f:(Uchar.t -\u003e Uchar.t option) -\u003e string -\u003e string\n\n(** Iterates over the Unicode code points in a string. *)\nval iter : f:(Uchar.t -\u003e unit) -\u003e string -\u003e unit\n\n(** Folds over the Unicode code points in a string. *)\nval fold : f:('acc -\u003e Uchar.t -\u003e 'acc) -\u003e init:'acc -\u003e string -\u003e 'acc\n\n(** Expands tab characters to spaces. *)\nval expand_tabs : tab_size:int -\u003e string -\u003e string\n\n(** Converts the first Unicode code point of a string to lowercase. *)\nval first_rune_to_lower : string -\u003e string\n\n(** Converts the first Unicode code point of a string to uppercase. *)\nval first_rune_to_upper : string -\u003e string\n\n(** Inserts a string into another at a specified index. *)\nval insert : src:string -\u003e index:int -\u003e string -\u003e string\n\n(** Partitions a string by the last occurrence of a separator. *)\nval last_partition : sep:string -\u003e string -\u003e string * string * string\n\n(** Left-justifies a string within a specified width. *)\nval left_justify : width:int -\u003e pad:string -\u003e string -\u003e string\n\n(** Partitions a string by the first occurrence of a separator. *)\nval partition : sep:string -\u003e string -\u003e string * string * string\n\n(** Right-justifies a string within a specified width. *)\nval right_justify : width:int -\u003e pad:string -\u003e string -\u003e string\n\n(** Returns the display width of a Unicode code point. *)\nval rune_width : Uchar.t -\u003e int\n\n(** Replaces invalid UTF-8 sequences in a string. *)\nval scrub : repl:string -\u003e string -\u003e string\n\n(** Randomly shuffles the Unicode code points in a string. *)\nval shuffle : string -\u003e string\n\n(** Shuffles a string using a provided random source. *)\nval shuffle_source : rand:Random.State.t -\u003e string -\u003e string\n\n(** Extracts a slice of a string by Unicode code point indices. *)\nval slice : start:int -\u003e end_:int -\u003e string -\u003e string\n\n(** Removes consecutive repeated characters that match a pattern. *)\nval squeeze : pattern:string -\u003e string -\u003e string\n```\n\n---\n\n## 📦 Installation\n\nUsing [opam](https://opam.ocaml.org/):\n\n```sh\nopam pin add stringx https://github.com/nao1215/stringx.git\n```\n\nOnce released:\n\n```sh\nopam install stringx\n```\n\n---\n\n## 🛠 Build from Source\n\n```sh\ngit clone https://github.com/nao1215/stringx.git\ncd stringx\n\nopam install . --deps-only -y\ndune build\n```\n\nRun tests:\n\n```sh\ndune runtest\n```\n\nGenerate documentation:\n\n```sh\nopam install odoc\ndune build @doc\nxdg-open _build/default/_doc/_html/index.html\n```\n\n---\n\n## 🧑‍💻 Contributing\n\n1. Format your code with `ocamlformat`.\n2. Make sure `dune runtest` passes.\n3. Add tests and documentation for new features.\n\nPull requests and issues welcome:\n👉 [https://github.com/nao1215/stringx/issues](https://github.com/nao1215/stringx/issues)\n\n---\n\n## 📝 License\n\nThis project is licensed under the [MIT License](./LICENSE).\n\n","funding_links":["https://github.com/sponsors/nao1215"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnao1215%2Fstringx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnao1215%2Fstringx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnao1215%2Fstringx/lists"}