{"id":20683147,"url":"https://github.com/chimehq/rearrange","last_synced_at":"2025-04-06T06:09:22.035Z","repository":{"id":46065776,"uuid":"192968531","full_name":"ChimeHQ/Rearrange","owner":"ChimeHQ","description":"Swift library for working with ranges types: NSRange, IndexSet, and String.Index","archived":false,"fork":false,"pushed_at":"2025-02-19T16:32:50.000Z","size":130,"stargazers_count":78,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-30T05:05:42.130Z","etag":null,"topics":["cocoa","foundation","macos","nstextview","swift","uitextview"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChimeHQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":["mattmassicotte"]}},"created_at":"2019-06-20T18:25:43.000Z","updated_at":"2025-02-19T16:32:54.000Z","dependencies_parsed_at":"2025-02-05T08:06:02.424Z","dependency_job_id":"a45efdc1-f628-430d-a9cd-a037dd715963","html_url":"https://github.com/ChimeHQ/Rearrange","commit_stats":{"total_commits":56,"total_committers":3,"mean_commits":"18.666666666666668","dds":0.0357142857142857,"last_synced_commit":"cbfa20245681132e90fa9b297fa33dd772468abd"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FRearrange","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FRearrange/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FRearrange/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChimeHQ%2FRearrange/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChimeHQ","download_url":"https://codeload.github.com/ChimeHQ/Rearrange/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441052,"owners_count":20939239,"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":["cocoa","foundation","macos","nstextview","swift","uitextview"],"created_at":"2024-11-16T22:15:36.176Z","updated_at":"2025-04-06T06:09:22.018Z","avatar_url":"https://github.com/ChimeHQ.png","language":"Swift","funding_links":["https://github.com/sponsors/mattmassicotte"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n[![Build Status][build status badge]][build status]\n[![Platforms][platforms badge]][platforms]\n[![Documentation][documentation badge]][documentation]\n[![Matrix][matrix badge]][matrix]\n\n\u003c/div\u003e\n\n# Rearrange\n\nRearrange is a collection of utilities for making it easier to work with `NSRange`, `IndexSet`, and `String.Index`.\n\nIf you need to work with `NSTextRange`/`UITextRange` or just TextKit in general, check out [Glyph][].\n\n[Glyph]: https://github.com/chimeHQ/Glyph \n\n## Integration\n\nSwift Package Manager:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/ChimeHQ/Rearrange\")\n]\n```\n\n## Types\n\n**RangeMutation**\n\nThis is a struct that encapsulates a single change to an `NSRange`. It's useful for serializing, queuing, or otherwise storing changes and applying them.\n\nYou can also use this class to tranform locations, `NSRange`, or even an `IndexSet`. This is handy for updating values as text is changed. This might seem easy, but there are a large number of edge cases that `RangeMutation` handles, including mutations that invalidate (for example completely delete) a range. \n\n## Extensions\n\n**NSRange**\n\n```swift\n// convenience\nstatic let zero: NSRange\nstatic let notFound: NSRange\nvar max: Int\n\n// shifting\nfunc shifted(by delta: Int) -\u003e NSRange?\nfunc shifted(endBy delta: Int) -\u003e NSRange?\nfunc shifted(startBy delta: Int) -\u003e NSRange?\n\n// mutating\nfunc clamped(to limit: Int) -\u003e NSRange\nfunc apply(_ change: RangeMutation) -\u003e NSRange?\n\n// working with Swift String\nfunc range(in string: String) -\u003e Range\u003cString.Index\u003e?\n```\n\n**IndexSet**\n\n```swift\ninit(integersIn range: NSRange)\ninit(ranges: [NSRange])\nmutating func insert(range: NSRange)\nmutating func insert(ranges: [NSRange])\nmutating func remove(integersIn range: NSRange)\nvar nsRangeView: [NSRange]\nfunc contains(integersIn range: NSRange) -\u003e Bool\nfunc intersects(integersIn range: NSRange) -\u003e Bool\nvar limitSpanningRange: NSRange?\n```\n\n**String**\n\n```swift\nsubscript(range: Range\u003cInt\u003e) -\u003e Substring?\nsubscript(range: NSRange) -\u003e Substring?\n```\n\n## Contributing and Collaboration\n\nI would love to hear from you! Issues or pull requests work great. Both a [Matrix space][matrix] and [Discord][discord] are available for live help, but I have a strong bias towards answering in the form of documentation. You can also find me on [mastodon](https://mastodon.social/@mattiem).\n\nI prefer collaboration, and would love to find ways to work together if you have a similar project.\n\nI prefer indentation with tabs for improved accessibility. But, I'd rather you use the system you want and make a PR than hesitate because of whitespace.\n\nBy participating in this project you agree to abide by the [Contributor Code of Conduct](CODE_OF_CONDUCT.md).\n\n[build status]: https://github.com/ChimeHQ/Rearrange/actions\n[build status badge]: https://github.com/ChimeHQ/Rearrange/workflows/CI/badge.svg\n[platforms]: https://swiftpackageindex.com/ChimeHQ/Rearrange\n[platforms badge]: https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FChimeHQ%2FRearrange%2Fbadge%3Ftype%3Dplatforms\n[documentation]: https://swiftpackageindex.com/ChimeHQ/Rearrange/main/documentation\n[documentation badge]: https://img.shields.io/badge/Documentation-DocC-blue\n[matrix]: https://matrix.to/#/%23chimehq%3Amatrix.org\n[matrix badge]: https://img.shields.io/matrix/chimehq%3Amatrix.org?label=Matrix\n[discord]: https://discord.gg/esFpX6sErJ\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchimehq%2Frearrange","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchimehq%2Frearrange","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchimehq%2Frearrange/lists"}