{"id":17224015,"url":"https://github.com/draveness/typeset","last_synced_at":"2025-04-05T15:06:16.065Z","repository":{"id":32673787,"uuid":"36262272","full_name":"draveness/Typeset","owner":"draveness","description":"Deal with AttributedString efficiently","archived":false,"fork":false,"pushed_at":"2020-07-07T08:39:27.000Z","size":11946,"stargazers_count":451,"open_issues_count":3,"forks_count":37,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-29T14:07:18.239Z","etag":null,"topics":["attributedstring","colorful","nsattributedstring","string","typeset"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mralex/babel-middleware","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/draveness.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-26T00:37:40.000Z","updated_at":"2025-03-23T20:51:15.000Z","dependencies_parsed_at":"2022-09-12T15:02:30.469Z","dependency_job_id":null,"html_url":"https://github.com/draveness/Typeset","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draveness%2FTypeset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draveness%2FTypeset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draveness%2FTypeset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draveness%2FTypeset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/draveness","download_url":"https://codeload.github.com/draveness/Typeset/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247353732,"owners_count":20925329,"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":["attributedstring","colorful","nsattributedstring","string","typeset"],"created_at":"2024-10-15T04:09:49.308Z","updated_at":"2025-04-05T15:06:16.047Z","avatar_url":"https://github.com/draveness.png","language":"Objective-C","readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"./images/Typeset.png\"\u003e\n\u003c/p\u003e\n\n[![Version](http://img.shields.io/cocoapods/v/Typeset.svg?style=flat)](http://cocoadocs.org/docsets/Typeset) [![Build Status](https://travis-ci.org/Draveness/Typeset.svg?branch=1.0.0)](https://travis-ci.org/Draveness/Typeset) ![MIT License](https://img.shields.io/github/license/mashape/apistatus.svg) ![Platform](https://img.shields.io/badge/platform-%20iOS%20-lightgrey.svg)\n\n----\n\nTypeset makes it easy to create `NSAttributedString`\n\n```\n@\"Hello typeset\".typeset\n   .match(@\"Hello\").fontSize(40)\n   .match(@\"type\").purple\n   .match(@\"set\").blue\n   .string;\n```\n\n# Demo\n\n![](./images/Typeset.gif)\n\n\n# Usage\n\n+ Method chaining\n\t+ All the method for typeset returns a `self` object to chaining itself.\n\n\t\t```\n\t\t@\"Hello typeset\".typeset\n\t\t   .match(@\"Hello\").fontSize(40)\n\t\t   .match(@\"type\").purple\n\t\t   .match(@\"set\").blue\n\t\t   .string;\n\t\t```\n\t\t\n\t\u003e call `typeset` method first and call `string` at last returns a `NSAttributedString`.\n\t\t\n+ `UILabel` and `UITextField` support\n\t+ Add `typesetBlock` to UILabel or `UITextField`, and you can directly set it's text style with:\n\n\t```objectivec\n\tlabel.typesetBlock = TSBlock(fontSize(40)\n\t                       .match(@\"type\").purple\n\t                       .match(@\"set\").blue);\n\tlabel.text = @\"Hello typeset, hello.\";\n\n    // If you type in this text field, it will color all the `1` in text field to red\n    textField.typesetBlock = TSBlock(match(@\"1\").red);\n\t```\n\n+ Construct complicated `NSMutableAttributedString`\n\n    ```objectivec\n    TSAttributedString(@\"Hello\".red, @\" \", @\"World\".blue);\n    ```\n\n+ Match part of string\n\t+ Typeset providing a series of method to match part of your string, you can use these method to select part of your string, and add attribute to it.\n\n\t```objectivec\n\t@\"Hello\".typeset.from(0).to(2).red.string;\n\t@\"Hello\".typeset.location(0).length(2).red.string;\n\t@\"Hello\".typeset.range(NSMakeRange(0,2)).red.string;\n\t@\"Hello\".typeset.match(@\"He\").red.string;\n\t```\n\t\n\t\u003e These lines of code all make `@\"He\"` of `@\"Hello\"` to red\n\t\n\t| Match Method                                           | Explain                                                |\n\t| ------------------------------------------------------ | ------------------------------------------------------ |\n\t| `from(NSUInteger)` `to(NSUInteger)`                    |                                                        |\n\t| `location(NSUInteger)` `length(NSUInteger)`            |                                                        |\n\t| `range(NSRange)`                                       |                                                        |\n    | `match(NSString *)`                                    | match the first substring                              |\n    | `matchWithOptions(NSString *, NSStringCompareOptions)` | match the first substring with options                 |\n\t| `matchAll(NSString)`                                   | match all the substring                                |\n    | `matchAllWithOptions(NSString *, NSStringCompareOptions)`| match all the substring with options                 |\n    | `all`                                                  | select all the string                                  |\n\n    + Match with pattern\n\n    | Match Method                                           | Pattern                    |\n    | ------------------------------------------------------ | -------------------------- |\n    | `matchAllWithPattern(NSString *pattern)`               |                            |\n    | `matchAllWithPatternAndOptions(NSString *pattern, NSRegularExpressionOptions options)` |  |\n    | `matchNumbers`                                         | \\d+                        |\n    | `matchLetters`                                         | [a-zA-Z]+                  |\n    | `matchLanguage(NSString *language)`                    | \\p{script=%@}              |\n    | `matchChinese`                                         | \\p{script=@\"Han\"}          |\n\n+ Convinient method\n\t+ If you don't want to change some part of the string, and only want to **change the color or the font**, you call call these methods directly without calling `typeset` first\n\n\t```objectivec\n\t@\"Hello\".red\n\t@\"Hello\".fontSize(20).red\n\t```\n\n\n## References\n\n### Attributes\n\n| Dictionary Key                      | `Typeset` Method                                       |\n| ----------------------------------- | ------------------------------------------------------ |\n| `NSFontAttributeName`               | `font(NSString fontName, CGFloat size)`                |\n|                                     | `fontSize(CGFloat size)`                               |\n|                                     | `fontName(NSString name)`                              |\n|                                     | `regular` `light` `italic` `thin` `bold`               |\n| `NSForegroundColorAttributeName`    | `color(UIColor color)`                                 |\n|                                     | `hexColor(CGFloat hexColor)`                           |\n|                                     | `black` `darkGray` `lightGray` `white` `gray` `red` `green` `blue` `cyan` `yellow` `magenta` `orange` `purple` `brown` `clear`                                |\n| `NSKernAttributeName`               | `kern(CGFloat kern)`                                   |\n| `NSUnderlineStyleAttributeName`     | `underline(NSUnderlineStyle underline)`                |\n| `NSUnderlineColorAttributeName`     | `underlineColor(UIColor *underlineColor)`              |\n| `NSBaselineOffsetAttributeName`     | `baseline(CGFloat baseline)`                           |\n| `NSStrikethroughStyleAttributeName` | `strikeThrough(NSUnderlineStyle strikeThrough)`        |\n| `NSStrikethroughColorAttributeName` | `strikeThroughColor(UIColor *underlineColor)`          |\n| `NSLinkAttributeName`               | `link(NSString *url)`                                  |\n| `NSLigatureAttributeName`           | `ligature(NSUInteger ligature)`                        |\n| `NSStrokeColorAttributeName`        | `strokeColor(UIColor *strokeColor)`                    |\n| `NSStrokeWidthAttributeName`        | `strokeWidth(CGFloat strokeWidth)`                     |\n| `NSShadowAttributeName`             | `shadow(NSShadow *shadow)`                             |\n| `NSTextEffectAttributeName`         | `textEffect(NSString *textEffect)`                     |\n| `NSObliquenessAttributeName`        | `obliqueness(CGFloat obliqueness)`                     |\n| `NSExpansionAttributeName`          | `expansion(CGFloat expansion)`                         |\n\n### NSParagraphStyle\n\n| `Typeset` Method                                       |\n| ------------------------------------------------------ |\n| `lineBreakMode(NSLineBreakMode lineBreakMode)`         |\n| `alignment(NSTextAlignment textAlignment)`             |\n| `lineSpacing(CGFloat lineSpacing)`                     |\n| `paragraphSpacing(CGFloat paragraphSpacing)`           |\n| `firstLineHeadIndent(CGFloat firstLineHeadIndent)`     |\n| `headIndent(CGFloat headIndent)`                       |\n| `tailIndent(CGFloat tailIndent)`                       |\n| `minimumLineHeight(CGFloat minimumLineHeight)`         |\n| `maximumLineHeight(CGFloat maximumLineHeight)`         |\n| `lineHeightMultiple(CGFloat lineHeightMultiple)`       |\n| `paragraphSpacingBefore(CGFloat paragraphSpacingBefore)` |\n| `hyphenationFactor(CGFloat hyphenationFactor)`         |\n| `defaultTabInterval(CGFloat defaultTabInterval)`       |\n| `baseWritingDirection(NSWritingDirection baseWritingDirection)`|\n| `allowsDefaultTighteningForTruncation(BOOL allowsDefaultTighteningForTruncation)`|\n\n## Installation \n\n### CocoaPods\n\n[CocoaPods](https://cocoapods.org/) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like Typeset in your projects. See the [Get Started section](https://cocoapods.org/#get_started) for more details.\n\n## Podfile\n\n```\npod \"Typeset\"\n```\n\n# Contribute\n\nFeel free to open an issue or pull request, if you need help or there is a bug.\n\n# Contact\n\n- Powered by [Draveness](http://github.com/draveness)\n\n# License\n\nTypeset is available under the MIT license. See the LICENSE file for more info.\n\n# Todo\n\n- Documentation\n- More features\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdraveness%2Ftypeset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdraveness%2Ftypeset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdraveness%2Ftypeset/lists"}