Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
4bf3e1c7c1 | |||
2d62dee4d0 | |||
3eb542bdfd | |||
5b87d0bf9a | |||
c822d2142e | |||
b80015bc4d | |||
b343ce830b |
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Veit Heller
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@@ -5,7 +5,7 @@ is a simple file path library for Carp.
|
||||
## Installation
|
||||
|
||||
```clojure
|
||||
(load "https://veitheller.de/git/carpentry/path@0.0.1")
|
||||
(load "https://veitheller.de/git/carpentry/path@0.0.2")
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
@@ -31,7 +31,7 @@
|
||||
<div class="module-description">
|
||||
<p>is a simple file path library for Carp.</p>
|
||||
<h2>Installation</h2>
|
||||
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/path@0.0.1")
|
||||
<pre><code class="language-clojure">(load "https://veitheller.de/git/carpentry/path@0.0.2")
|
||||
</code></pre>
|
||||
<h3>Usage</h3>
|
||||
<p>The <code>Path</code> module mostly operates on <code>String</code> arguments. It allows you to
|
||||
@@ -70,7 +70,7 @@ has some functions to work with the <code>PATH</code> environment variable.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Maybe String))
|
||||
(λ [(Ref String a)] (Maybe String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(absolute p)
|
||||
@@ -90,14 +90,14 @@ has some functions to work with the <code>PATH</code> environment variable.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Bool)
|
||||
(λ [(Ref String a)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(absolute? p)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>checks whether a path is absolute.</p>
|
||||
<p>As such, it is the inverse to <a href="#relative">relative</a>.</p>
|
||||
<p>As such, it is the inverse to <a href="#relative?">relative?</a>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
@@ -111,7 +111,7 @@ has some functions to work with the <code>PATH</code> environment variable.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] String)
|
||||
(λ [(Ref String a), (Ref String b)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(add-extension p ext)
|
||||
@@ -131,7 +131,7 @@ has some functions to work with the <code>PATH</code> environment variable.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(basename p)
|
||||
@@ -172,7 +172,7 @@ which it can fail are OS-dependent, but it should happen relatively rare.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(drop-extension p)
|
||||
@@ -193,7 +193,7 @@ is none.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Maybe String))
|
||||
(λ [(Ref String a)] (Maybe String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(extension p)
|
||||
@@ -213,7 +213,7 @@ is none.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Maybe String))
|
||||
(λ [(Ref String a)] (Maybe String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(filename p)
|
||||
@@ -254,7 +254,7 @@ is none.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Bool)
|
||||
(λ [(Ref String a)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(has-extension? p)
|
||||
@@ -274,7 +274,7 @@ is none.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] Bool)
|
||||
(λ [(Ref String a), (Ref String b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(is-extension? p ext)
|
||||
@@ -294,7 +294,7 @@ is none.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array String))] String)
|
||||
(λ [(Ref (Array String) a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(join ps)
|
||||
@@ -335,14 +335,14 @@ is none.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Bool)
|
||||
(λ [(Ref String a)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(relative? p)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>checks whether a path is relative.</p>
|
||||
<p>As such, it is the inverse to <a href="#absolute">absolute</a>.</p>
|
||||
<p>As such, it is the inverse to <a href="#absolute?">absolute?</a>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
@@ -356,7 +356,7 @@ is none.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] String)
|
||||
(λ [(Ref String a), (Ref String b)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(replace-extension p ext)
|
||||
@@ -437,7 +437,7 @@ variable we use on this OS.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Char] Bool)
|
||||
(λ [(Ref Char StaticLifetime)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(separator? c)
|
||||
@@ -478,7 +478,7 @@ variable we use on this OS.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Array String))
|
||||
(λ [(Ref String a)] (Array String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(split p)
|
||||
@@ -499,7 +499,7 @@ variable we use on this OS.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Maybe (Pair String String)))
|
||||
(λ [(Ref String a)] (Maybe (Pair String String)))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(split-extension p)
|
||||
@@ -536,7 +536,7 @@ the extension.</p>
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Array String))
|
||||
(λ [(Ref String a)] (Array String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(split-search-path p)
|
||||
|
@@ -1,13 +1,10 @@
|
||||
(load "path.carp")
|
||||
|
||||
(defndynamic gendocs []
|
||||
(do
|
||||
(Project.config "title" "path")
|
||||
(Project.config "docs-directory" "./docs/")
|
||||
(Project.config "docs-logo" "")
|
||||
(Project.config "docs-styling" "style.css")
|
||||
(Project.config "docs-generate-index" false)
|
||||
(save-docs Path)))
|
||||
(save-docs Path)
|
||||
|
||||
(gendocs)
|
||||
(quit)
|
||||
|
18
path.carp
18
path.carp
@@ -3,7 +3,7 @@
|
||||
## Installation
|
||||
|
||||
```clojure
|
||||
(load \"https://veitheller.de/git/carpentry/path@0.0.1\")
|
||||
(load \"https://veitheller.de/git/carpentry/path@0.0.2\")
|
||||
```
|
||||
|
||||
### Usage
|
||||
@@ -16,7 +16,7 @@ It assumes either Windows or POSIX-style separators.")
|
||||
(defmodule Path
|
||||
(doc absolute? "checks whether a path is absolute.
|
||||
|
||||
As such, it is the inverse to [relative](#relative).")
|
||||
As such, it is the inverse to [relative?](#relative?).")
|
||||
(doc separator "is the default separator we use on this OS.")
|
||||
(doc separators "is the possible separators we could use on this OS.")
|
||||
(doc search-path-separator "is the separator for the `PATH` environment
|
||||
@@ -32,7 +32,7 @@ variable we use on this OS.")
|
||||
(def search-path-separator \;)
|
||||
(def extension-pat #"\.[^\\/\.]*$")
|
||||
(def sep-string "\\"))
|
||||
(not-on-windows
|
||||
(posix-only
|
||||
(defn absolute? [p] (String.starts-with? p "/"))
|
||||
(def separator \/)
|
||||
(def separators [\/])
|
||||
@@ -42,7 +42,7 @@ variable we use on this OS.")
|
||||
|
||||
(doc relative? "checks whether a path is relative.
|
||||
|
||||
As such, it is the inverse to [absolute](#absolute).")
|
||||
As such, it is the inverse to [absolute?](#absolute?).")
|
||||
(defn relative? [p] (not (absolute? p)))
|
||||
|
||||
(doc separator? "checks whether the character `c` is a path separator on this
|
||||
@@ -85,7 +85,7 @@ It will return `Nothing` if an empty string is passed.")
|
||||
(doc basename "gets the basename of the path `p`.")
|
||||
(defn basename [p]
|
||||
(let [split (split p)
|
||||
but-last (Array.prefix-array &split (dec (Array.length &split)))]
|
||||
but-last (Array.prefix &split (dec (Array.length &split)))]
|
||||
(String.join sep-string &but-last)))
|
||||
|
||||
(doc split-extension "splits the path `p` on its extension.
|
||||
@@ -113,7 +113,7 @@ Examples on POSIX:
|
||||
(let [i (Pattern.find extension-pat p)]
|
||||
(if (= -1 i)
|
||||
(Maybe.Nothing)
|
||||
(Maybe.Just (Pair.init (prefix-string p i) (suffix-string p (inc i)))))))
|
||||
(Maybe.Just (Pair.init (prefix p i) (suffix p (inc i)))))))
|
||||
|
||||
(doc extension "gets the extension of a file as a `Maybe`.")
|
||||
(defn extension [p]
|
||||
@@ -127,9 +127,9 @@ Examples on POSIX:
|
||||
(doc drop-extension "drops the extension of a path `p`. Does nothing if there
|
||||
is none.")
|
||||
(defn drop-extension [p]
|
||||
@(match (split-extension p)
|
||||
(Maybe.Nothing) p
|
||||
(Maybe.Just pair) (Pair.a &pair)))
|
||||
(match (split-extension p)
|
||||
(Maybe.Nothing) @p
|
||||
(Maybe.Just pair) @(Pair.a &pair)))
|
||||
|
||||
(doc add-extension "adds an extension `ext` to a path `p`.")
|
||||
(defn add-extension [p ext] (String.concat &[@p @"." @ext]))
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
(use-all Path Test)
|
||||
|
||||
(if (not (Dynamic.or (= "windows" (os)) (= "mingw32" (os))))
|
||||
(posix-only
|
||||
(deftest test
|
||||
(assert-equal test
|
||||
"path/joined"
|
||||
@@ -41,11 +41,11 @@
|
||||
"cwd works"
|
||||
)
|
||||
; TODO why does this test not work?
|
||||
;(assert-equal test
|
||||
; "file"
|
||||
; &(drop-extension "file.txt")
|
||||
; "drop-extension works if there is an extension"
|
||||
;)
|
||||
(assert-equal test
|
||||
"file"
|
||||
&(drop-extension "file.txt")
|
||||
"drop-extension works if there is an extension"
|
||||
)
|
||||
(assert-equal test
|
||||
"file"
|
||||
&(drop-extension "file")
|
||||
@@ -87,7 +87,7 @@
|
||||
)
|
||||
)
|
||||
())
|
||||
(if (Dynamic.or (= "windows" (os)) (= "mingw32" (os)))
|
||||
(windows-only
|
||||
(deftest test
|
||||
(assert-true test
|
||||
false
|
||||
|
Reference in New Issue
Block a user