Giter Site home page Giter Site logo

urlparser's Introduction

Elmish-urlParser: urlParser extras for Elmish apps.

Windows Build NuGet version

Elmish-UrlParser implements parser combinators for turning URLs into strongly-typed data.

For more information see the docs.

Installation

paket add Fable.Elmish.UrlParser

Building

With .NET Core SDK v6:

fotnet fsi build.fsx

urlparser's People

Contributors

dependabot[bot] avatar et1975 avatar mangelmaxime avatar theor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

urlparser's Issues

[<RequireQualifiedAccess>] on functions

Yall opposed to adding [<RequireQualifiedAccess>] for functions like map, oneOf, parseHash, etc?

Also, any reason as to why so conservative when naming functions like s and i32?

Please don't take this as crapping on the library (it's pretty awesome) but I wonder if adoption is not as big as Feliz.Router... due to the cryptic nature of some of these function names...

And maybe placing </> in a module that one must open kind of like fstoolkit-errorhandling does it...

Again, just observations since I am comparing urlParser (elmish.browser) with Feliz.Router

Documentation/Hint on each function

I think I have suggested renaming s and str to something more userfriendly but got rejected =/
Can we instead provide documentation with /// on each of the functions? I think the documentation in the Elmish.UrlParser github page is very helpful, so maybe adding it to the function would also provide value...

* s combinator for a static string we expect to find in the URL,
* </> combinator to capture a slash in the URL,
* str combinator to extract a string,
* i32 combinator to attempt to parse an int.
* top combinator that takes nothing.
* remaining combinator to get the remaining parts of the URL

I tend to shadow like this to provide clarity:

// combinator for a static string we expect to find in the URL
let matchString = UrlParser.s
// combinator to extract a string
let parseString = UrlParser.str
// combinator to attempt to parse and Int32
let parseInt32 = UrlParser.i32

Fable 4.0 breaks parseParams

Before the Fable 4.0 update we did:

let urlParser location = parsePath pageParser location

but now we have to do

let urlParser (location:Browser.Types.Location) =
    parse pageParser location.pathname (parseParams (location.search.Replace("?","")))

It looks like the ? is no longer handled automatically.

/cc @et1975 @alfonsogarciacaro @MangelMaxime @tforkmann

parseParams doesn't handle empty or null case

Description

I am seeing this line throws when used via Navigation when query string is null. It assumes queryString has some value

querystring.Substring(1).Split('&')

It just looks wrong to me.

Related information

  • elmish version: 4.0
  • fable-compiler version: 4.0
  • fable-core version: 4.0
  • Operating system: macos

Suggestion : parser that takes everything remaining ?

I recently had a case where I needed to consume the remaining elements of an url that might contain slashes. this is the parser I wrote :

    let remaining: Parser<(string -> 'a), 'a> = (fun s ->
        [
          { visited = List.concat [s.visited; s.unvisited]
            unvisited = []
            args = s.args
            value = s.value (String.Join("/", s.unvisited))}
        ])

usage:

type Route =
    | Home
    | Graph of string
// #/graph/lorem/ipsum
oneOf [ map Route.Graph (s "graph" </> remaining)
        map Route.Home top ]

that started with what looked like a bug in the parsing, but was due to the payload containing a /. I thought that might be worth documenting at least, maybe adding to the lib ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.