/Guitar

A Cross-Platform String Library Written in Swift.

Primary LanguageShellMIT LicenseMIT

Guitar

A Cross-Platform String Library Written in Swift.

Build Status Documentation Platform

CocoaPods Carthage Compatible SwiftPM Compatible CocoaPods CocoaPods

About

This library seeks to add common string manipulation functions that are needed in both mobile and server-side development, but are missing in Swift's Foundation library.

The full documentation can be found at http://www.sabintsev.com/Guitar/.

Project Status

  • Release Stage: Alpha (until v0.1.0)
  • Development Status: Active Development (as of March 1, 2017)
  • Contributions are highly encouraged.

Roadmap

Functions

  • Boolean Functions (isAlpha, isNumeric, isUppercase, etc.)
  • Case Functions (camelCased, pascalCased, kebabCased, etc.)
  • Character Functions (first, length, reverse, etc.)
  • Latinization Functions
  • HTML Manipulation Functions
  • Padding Functions (padLeft, padRight, pad)
  • Regular Expressions / Regex (Pure Swift Implementation)
  • Trimming Functions (trimLeft, trimRight, prefixed, etc.)

Documentation

Dependency Management

  • Carthage Support
  • CocoaPods Support
  • Swift Package Manager

Testing

  • Continuous Integration with Buddy Build
  • SwiftLint Integration
  • Unit Tests

Installation Instructions

CocoaPods

pod 'Guitar'

Carthage

github "ArtSabintsev/Guitar"

Swift Package Manager

.Package(url: "https://github.com/ArtSabintsev/Guitar.git")

Implemented Functions

Boolean Operations

isAlpha()

let string = "HelloWorld"
string.isAlpha() // True

let string = "Hell0World"
string.isAlpha() // False

isAlphanumeric()

let string = "HelloWorld"
string.isAlphanumeric() // True

let string = "Hell0World"
string.isAlphanumeric() // True

let string = "Hell0 World"
string.isAlphanumeric() // False

isCapitalized()

let string = "Hello World"
string.isCapitalized() // True

let string = "hello World"
string.isCapitalized() // False

let string = "Hello-World"
string.isCapitalized() // True

isDecapitalized()

let string = "hello World"
string.isDecapitalized() // True

let string = "Hello World"
string.isDecapitalized() // False

let string = "hello-World"
string.isDecapitalized() // True

isLowercased()

// Note, Swift treats non-alphabetical characters as Uppercased.

let string = "helloworld"
string.isLowercased() // True

let string = "hello world"
string.isLowercased() // False

let string = "hello-world"
string.isLowercased() // False

isNumeric()

let string = "73110"
string.isNumeric() // True

let string = "73110 1337"
string.isNumeric() // False

let string = "73110World"
string.isNumeric() // False

isUpppercased()

// Note, Swift treats non-alphabetical characters as Uppercased.

let string = "HELLOWORLD"
string.isUpppercased() // True

let string = "HELLO WORLD"
string.isUpppercased() // True

let string = "HELLO-W0RLD"
string.isUpppercased() // True

let string = "HeLLoW0RLD"
string.isUpppercased() // False

Case Operations

camelCased()

let string = "Hello World"
string.camelCased() // "helloWorld"

let string = "hello_world"
string.camelCased() // "helloWorld"

decapitalized()

// Implementation is currently broken.

kebabCased()

let string = "Hello World"
string.kebabCased() // "-Hello-World-"

let string = "hello_world"
string.kebabCased() // "-hello-world-"

pascalCased()

let string = "Hello World"
string.pascalCased() // "HelloWorld"

let string = "hello_world"
string.pascalCased() // "HelloWorld"

slugCased()

let string = "Hello World"
string.slugCased() // "Hello-World"

snakeCased()

let string = "Hello World"
string.snakeCased() // "Hello_World"

swapCased()

let string = "Hello World"
string.swapCased() // "hELLO wORLD"

Character Operations

first()

let string = "Hello World"
string.first() // "H"

last()

let string = "Hello World"
string.last() // "d"

length()

let string = "Hello World"
string.length() // "11"

reversed()

let string = "Hello World"
string.reversed() // "dlroW olleH"

Padding Operations

padLeft()

let string = "Hello World" // 11 Characters
string.padLeft(length: 15) // "    Hello World"

let string = "Hello World" // 11 Characters
string.padLeft(length: 15, withToken: "*") // "****Hello World"

let string = "Hello World" // 11 Characters
string.padLeft(length: 5) // Returns the original string, "Hello World"

padRight()

let string = "Hello World" // 11 Characters
string.padRight(length: 15) // "Hello World    "

let string = "Hello World" // 11 Characters
string.padRight(length: 15, withToken: "*") // "Hello World****"

let string = "Hello World" // 11 Characters
string.padRight(length: 5) // Returns the original string, "Hello World"

pad()

let string = "Hello World" // 11 Characters
string.pad(length: 15) // "  Hello World  "

let string = "Hello World" // 11 Characters
string.pad(length: 5) // Returns the original string, "Hello World"

let string = "Hello World" // 11 Characters
string.pad(length: 15, withToken: "*") // "**Hello World**"

/* Note: If the difference between the final length
 and number of characters in the original string is odd,
 the string is padded extra on the right side.
 */
let string = "Hello World" // 11 Characters
string.pad(length: 16) // "  Hello World   "

let string = "Hello World" // 11 Characters
string.pad(length: 16) // "**Hello World***"

Trimming Operations

prefixed()

let string = "Hello World"
string.prefixed(length: 7) // "Hello W"

suffixed()

let string = "Hello World"
string.suffixed(length: 7) // "o World"

trimLeft()

let string = "Hello World"
string.trimLeft(length: 7) // "orld"

trimRight()

let string = "Hello World"
string.trimRight(length: 7) // "Hell"

truncated()

let string = "Hello World"
string.truncated(length: 7) // "Hell..." (Appends an ellipsis, ..., to the end of the string.)

Inspiration

This project was inspired by Voca.

Created and maintained by

Arthur Ariel Sabintsev