Path library for Swift

Overview

Build

SimplePath

SimplePath is a library for working with file paths in Swift. It borrows heavily from the path libraries of other languages such as Go, PHP, C and Perl, and runtimes such as Node.js.

This library doesn't try to hide the fact that file paths are strings. Most of its functions take strings as arguments and return strings.

Functions

Path.join([components])

Builds a path string by joining components, adding directory separators where necessary.

let path = Path.join([
    "/var/www",
    "website",
    "robots.txt"
])

// path -> /var/www/website/robots.txt

Path.split(path)

Returns all components of a given path.

let components = Path.split("/storage/images/0001.jpg")

// components -> [
//   "/",
//   "storage",
//   "images",
//   "0001.jpg"
// ]

Path.basename(path)

Returns the last component of a path. Usually a file name.

let base = Path.basename("assets/images/logo.png")

// base -> "logo.png"
let base = Path.basename("assets/images/logo.png", ext: "png")

// base -> "logo"

Path.dirname(path)

Returns the parent directory of a path.

let dir = Path.dirname("/var/data/map.bin")

// dir -> "/var/data"

Path.extname(path)

Gets the extension of a path.

let ext = Path.extname("assets/sfx/drumroll.wav")

// ext -> "wav"
let ext = Path.extname("assets/sfx")

// ext -> nil

Path.format([elements])

Builds a path, given named elements of the path.

let path = Path.format([
    .dir:  "assets/icons",
    .base: "settings.png"
])

// path -> "assets/icons/settings.png"
let path = Path.format([
    .dir:  "assets/vector",
    .base: "logo"
    .ext:  "svg"
])

// path -> "assets/vector/logo.svg"

Path.isAbsolute(path) and Path.isRelative(path)

Can be used for checking if a path is absolute or relative.

Path.isAbsolute("/var/logs/test.log") // -> true
Path.isRelative("cache/images/1.bin") // -> true

Path.exists(path)

Returns true if the path exists.

Path.exists("/path/to/existing/file.txt") // -> true

Path.isFile(path)

Returns true if the path exists and is a regular file.

Path.isFile("/path/to/existing/file.txt") // -> true

Path.isDir(path)

Returns true if the path exists and is a directory.

Path.isDir("/path/to/existing/dir") // -> true

Extending

If you think SimplePath is missing important functionalty I suggest you follow these steps:

  1. Implement such functionality as an extension.
  2. And if you believe that the functionality is highly reusable, feel free to contribute it back to the project by opening a pull request.

License

This library is licensed under the MIT license.

You might also like...
Type-safe observable values and collections in Swift

GlueKit ⚠️ WARNING ⚠️ This project is in a prerelease state. There is active work going on that will result in API changes that can/will break code wh

💊 Syntactic sugar for Swift do-try-catch

Fallback Syntactic sugar for Swift do-try-catch. At a Glance value = try fallback( try get("A"), try get("B"), try get("C"), try get("D") ) is

A Swift micro-framework to easily deal with weak references to self inside closures

WeakableSelf Context Closures are one of Swift must-have features, and Swift developers are aware of how tricky they can be when they capture the refe

Measure Swift code metrics and get reports in Xcode, Jenkins and other CI platforms.
Measure Swift code metrics and get reports in Xcode, Jenkins and other CI platforms.

Taylor ⚠️ Taylor is DEPRECATED. Use SwiftLint instead. A tool aimed to increase Swift code quality, by checking for conformance to code metrics. Taylo

Swift-lint-plugin - A SwiftPM plugin that adds a linting command

SwiftLintPlugin This is a SwiftPM plugin that adds a lint command. SwiftPM plugi

Aplicação Basica em Swift desenvolvida com o intuito de aplicar os conceitos estudados
Aplicação Basica em Swift desenvolvida com o intuito de aplicar os conceitos estudados

Via Cep iOS Sobre - Interface do Usuario - Tecnologias - Requisitos - Autor Projeto 🛑 FINALIZADO 🛑 Sobre A Aplicação consiste em fazer buscas usando

File management and path analysis for Swift
File management and path analysis for Swift

Pathos offers cross-platform virtual file system APIs for Swift. Pathos is implement from ground-up with on each OS's native API. It has zero dependen

A Swift wrapper for system shell over posix_spawn with search path and env support.

AuxiliaryExecute A Swift wrapper for system shell over posix_spawn with search path and env support. Usage import AuxiliaryExecute AuxiliaryExecute.l

Unreachable code path optimization hint for Swift
Unreachable code path optimization hint for Swift

Unreachable is a Swift µframework that allows for letting the compiler know when a code path is unreachable. Build Status Installation Compatibility S

A simple to use iOS/tvOS/watchOS SDK to help get you off the ground quickly and efficiently with your Elastic Path Commerce Cloud written in Swift.

Elastic Path Commerce Cloud iOS Swift SDK A simple to use iOS/tvOS/watchOS SDK to help get you off the ground quickly and efficiently with your Elasti

The fast path to autolayout views in code
The fast path to autolayout views in code

NorthLayout The fast path to autolayout views in code Talks https://speakerdeck.com/banjun/auto-layout-with-an-extended-visual-format-language at AltC

Easy and maintainable app navigation with path based routing for SwiftUI.

Easy and maintainable app navigation with path based routing for SwiftUI.

Path based routing in SwiftUI

Easy and maintainable app navigation with path based routing for SwiftUI. With SwiftUI Router you can power your SwiftUI app with path based routing.

SwiftUI:Using Shape & Path to Draw Taiwan Meme Cat

SwiftUI:Using Shape & Path to Draw Taiwan Meme Cat Using SwiftUI's Shape & Path to draw sticker「Taiwan Meme Cat」from Instagram:@taiwanmemecat! SwiftUI

A nice tutorial like the one introduced in the Path 3.X App
A nice tutorial like the one introduced in the Path 3.X App

ICETutorial Welcome to ICETutorial. This small project is an implementation of the newly tutorial introduced by the Path 3.X app. Very simple and effi

AVXCAssets Generator takes path for your assets images and creates appiconset and imageset for you in just one click
AVXCAssets Generator takes path for your assets images and creates appiconset and imageset for you in just one click

AVXCAssets Generator Often while developing an app, We ran into a condition when we need to scale images to each and every aspect ratios for icons and

AppKitFocusOverlay - Add hotkey(s) to display the key focus path for any window in your (running) AppKit application
AppKitFocusOverlay - Add hotkey(s) to display the key focus path for any window in your (running) AppKit application

AppKitFocusOverlay A simple package for displaying the current focus target path

Tools for SwiftUI that helps perform Path and Shape animations, such us morphing circle or shape transformations
Tools for SwiftUI that helps perform Path and Shape animations, such us morphing circle or shape transformations

SwiftUI+PathAnimations 🔵 Introduction This packages contains SimilarShape and InterpolatedShape, both can be used to achieve shapes animations with S

NintendoSwitch-BezierPath-Example - Nintendo Switch Bezier Path Example

NintendoSwitch-BezierPath-Example An example app that demonstrates the use of Be

Owner
Ramon Torres
Ninja
Ramon Torres
iOS library to help detecting retain cycles in runtime.

FBRetainCycleDetector An iOS library that finds retain cycles using runtime analysis. About Retain cycles are one of the most common ways of creating

Facebook 4.1k Dec 26, 2022
Aardvark is a library that makes it dead simple to create actionable bug reports.

Aardvark Aardvark makes it dead simple to create actionable bug reports. Aardvark is made up of a collection of frameworks that provide different bug

Square 257 Dec 19, 2022
A dynamic library for Cornerstone macOS.

Cornerstone-Hook A dynamic library for Cornerstone macOS. Screenshot Overview Quick Start sudo ./install.sh Install or Upgrade CornerstoneStart.app su

ivar 3 Oct 8, 2022
A library that enables dynamically rebinding symbols in Mach-O binaries running on iOS.

fishhook fishhook is a very simple library that enables dynamically rebinding symbols in Mach-O binaries running on iOS in the simulator and on device

Meta 4.9k Jan 8, 2023
Lint anything by combining the power of Swift & regular expressions.

Installation • Getting Started • Configuration • Xcode Build Script • Donation • Issues • Regex Cheat Sheet • License AnyLint Lint any project in any

Flinesoft 116 Sep 24, 2022
A tool for Swift code modification intermediating between code generation and formatting.

swift-mod A tool for Swift code modification intermediating between code generation and formatting. Overview swift-mod is a tool for Swift code modifi

Ryo Aoyama 95 Nov 3, 2022
A command-line tool and Xcode Extension for formatting Swift code

Table of Contents What? Why? How? Command-line tool Xcode source editor extension Xcode build phase Via Applescript VSCode plugin Sublime Text plugin

Nick Lockwood 6.3k Jan 8, 2023
A tool to enforce Swift style and conventions.

SwiftLint A tool to enforce Swift style and conventions, loosely based on the now archived GitHub Swift Style Guide. SwiftLint enforces the style guid

Realm 16.9k Jan 9, 2023
An Xcode formatter plug-in to format your swift code.

Swimat Swimat is an Xcode plug-in to format your Swift code. Preview Installation There are three way to install. Install via homebrew-cask # Homebrew

Jintin 1.6k Jan 7, 2023
Cross-platform static analyzer and linter for Swift.

Wiki • Installation • Usage • Features • Developers • License Tailor is a cross-platform static analysis and lint tool for source code written in Appl

Sleekbyte 1.4k Dec 19, 2022