Numerous Problems Multiplied
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

elixir-stdlib-js

1.4.1 • Public • Published

Elixir Standard Library Helpers

Why? I want to use the same API on the front and back end while being immutable

All objects and arrays are copied and the originals are never mutated. Keys are camel cased instead of snake cased. Some Elixir specific functions have not been included.

Codeship Status for AdamBrodzinski/elixir-stdlib-js

IO

Map

  • Map.delete
  • Map.drop
  • Map.equal
  • Map.get
  • Map.hasKey
  • Map.keys
  • Map.merge
  • Map.new/0
  • Map.new/1
  • Map.pop
  • Map.put
  • Map.putNew
  • Map.split
  • Map.take
  • Map.toList
  • Map.update
  • Map.values
  • Elixir docs - Map

String

  • String.at
  • String.capitalize
  • String.contains
  • String.downcase
  • String.duplicate

Function piping

Elixir encourages the use of function "pipelines" and has a similar style to lodashes _.chain method. For convenience we've exposed a pipe function that aliases chain. We've also mixed in the IO.inspect function so that you can call .inspect() without any extra work. To add a function to the pipeline just use the .run(yourFunc, arg1, arg2) to include it. This works the same as |> yourFunc(arg1, arg2) in Elixir.

function stripChars(str, char) {
  return str.replace(char, "")
}

let phone = pipe("555-222-000 ")
  .run(String.trim)
  .run(stripChars, "-")
  .inspect()
  .run(str => "+1" + str)
  .value()

>>> "+1555222000"

See history.md for changes and updates

install

npm i elixir-stdlib-js

Downloadsweekly downloads

0

version

1.4.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability