Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leifg/backports
Ensure backwards compatibility even if newer functions are used
https://github.com/leifg/backports
Last synced: 3 months ago
JSON representation
Ensure backwards compatibility even if newer functions are used
- Host: GitHub
- URL: https://github.com/leifg/backports
- Owner: leifg
- License: mit
- Created: 2017-06-01T18:53:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-06T11:17:27.000Z (over 7 years ago)
- Last Synced: 2024-10-04T03:49:13.381Z (3 months ago)
- Language: Elixir
- Homepage:
- Size: 43 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Use new functions in Elixir 1.1 and 1.2. (Macros)
- fucking-awesome-elixir - backports - Use new functions in Elixir 1.1 and 1.2. (Macros)
- awesome-elixir - backports - Use new functions in Elixir 1.1 and 1.2. (Macros)
README
# Backports
Tooling to make it possible to run "new" code in old Elixir versions.
Currently the following functions not available before 1.3 can be backported:
- `String.trim`
- `String.to_charlist`
- `String.pad_leading`
- `String.pad_trailing`
can replace `trim` and `to_charlist` functions which were not available prior to Elixir 1.3.## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `backports` to your list of dependencies in `mix.exs`:```elixir
def deps do
[{:backports, "~> 0.2.0"}]
end
```## Usage
Whatever module uses a function that is not available, just include `Backports`
This code will work in Elixir 1.1 and 1.2
```elixir
defmodule Foo do
use Backportsdef bar do
String.trim(" amazing ")
end
end
```