项目作者: ttak0422

项目描述 :
Elm inspired URL builder. Sample Application ->
高级语言: F#
项目地址: git://github.com/ttak0422/Elmish.UrlBuilder.git
创建时间: 2019-04-06T09:26:11Z
项目社区:https://github.com/ttak0422/Elmish.UrlBuilder

开源协议:Apache License 2.0

下载


Elmish.UrlBuilder

NuGet version
Codacy Badge

  • master

    Build status
    Build Status

  • dev

    Build status
    Build Status

About

elm/url for elmish/elmish

Build

  1. ./fake.sh build

Info

URLs

  1. type Url =
  2. { Protocol : Protocol
  3. Host : string
  4. Port : Option<int>
  5. Path : string
  6. Query : Option<string>
  7. Fragment : Option<string> }
  1. type Protocol =
  2. | Http
  3. | Https
  1. toString // Url -> string
  1. fromString // string -> Option<Url>
  2. // sample
  3. fromString "https://example.com:443/"
  4. (*
  5. Some { Protocol = Https
  6. Host = "example.com"
  7. Port = Some 443
  8. Path = "/"
  9. Query = None
  10. Fragment = None }
  11. *)
  12. fromString "https://example.com/hats?q=top%20hat"
  13. (*
  14. Some { Protocol = Https
  15. Host = "example.com"
  16. Port = None
  17. Path = "/hats"
  18. Query = Some "q=top%20hat"
  19. Fragment = None }
  20. *)
  21. fromString "http://example.com/core/List/#map"
  22. (*
  23. Some { Protocol = Http
  24. Host = "example.com"
  25. Port = None
  26. Path = "/core/List"
  27. Query = None
  28. Fragment = Some "map" }
  29. *)
  30. fromString "example.com:443" = None
  31. fromString "http://tom@example.com" = None
  32. fromString "http://#cats" = None

Percent-Encoding

  1. percentEncode // string -> string
  2. // sample
  3. percentEncode "hat" = "hat"
  4. percentEncode "to be" = "to%20be"
  5. percentEncode "99%" = "99%25"
  6. percentEncode "$" = "%24"
  7. percentEncode "¢" = "%C2%A2"
  8. percentEncode "€" = "%E2%82%AC"
  1. percentDecode // string -> Option<string>
  2. // sample
  3. percentDecode "hat" = Some "hat"
  4. percentDecode "to%20be" = Some "to be"
  5. percentDecode "99%25" = Some "99%"
  6. percentDecode "%24" = Some "$"
  7. percentDecode "%C2%A2" = Some "¢"
  8. percentDecode "%E2%82%AC" = Some "€"
  9. percentDecode "%" = None
  10. percentDecode "%XY" = None
  11. percentDecode "%C2" = None

Queries

The following function name is different from elm/url

  • str (in elm/url is string)
  • i32 (in elm/url is int)
  1. type QueryPatameter = QueryPatameter of keyValue : string * string
  1. str // string -> string -> QueryParameter
  2. // sample
  3. absolute [ "products" ] [ str "search" "hat" ]
  4. (*
  5. "/products?search=hat"
  6. *)
  7. absolute [ "products" ] [ str "search" "coffee table" ]
  8. (*
  9. "/products?search=coffee%20table"
  10. *)
  1. i32 // string -> int -> QueryParameter
  2. // sample
  3. absolute [ "products" ] [ str "search" "hat"; i32 "page" 2 ]
  4. (*
  5. "/products?search=hat&page=2"
  6. *)
  1. toQuery // QueryParameter list -> string
  2. // sample
  3. toQuery [ str "search" "hat" ]
  4. (*
  5. "?search=hat"
  6. *)
  7. toQuery [ str "search" "coffee table" ]
  8. (*
  9. "?search=coffee%20table"
  10. *)
  11. toQuery [ str "search" "hat"; int "page" 2 ]
  12. (*
  13. "?search=hat&page=2"
  14. *)
  15. toQuery []
  16. (*
  17. ""
  18. *)

Builder

  1. type Root =
  2. | Absolute
  3. | Relative
  4. | CrossOrigin of string
  1. abusolute // string list -> QueryParameter list -> strnig
  2. // sample
  3. absolute [] []
  4. (*
  5. "/"
  6. *)
  7. absolute [ "packages"; "elmish"; "elmish" ] []
  8. (*
  9. "/packages/elmish/elmish
  10. *)
  11. absolute [ "blog"; string 42 ] []
  12. (*
  13. "/blog/42"
  14. *)
  15. absolute [ "products" ] [ str "search" "hat"; i32 "page" 2 ]
  16. (*
  17. "/products?search=hat&page=2"
  18. *)
  1. relative // string list -> QueryParameter list -> string
  2. // sample
  3. relative [] []
  4. (*
  5. ""
  6. *)
  7. relative [ "elmish"; "elmish" ] []
  8. (*
  9. "elmish/elmish"
  10. *)
  11. relative [ "blog"; string 42 ] []
  12. (*
  13. "blog/42"
  14. *)
  15. relative [ "products" ] [ str "search" "hat"; i32 "page" 2 ]
  16. (*
  17. "products?search=hat&page=2"
  18. *)
  1. crossOrigin // string -> string list -> QueryParameter list -> string
  2. // sample
  3. crossOrigin "https://example.com" [ "products" ] []
  4. (*
  5. "https://example.com/products"
  6. *)
  7. crossOrigin "https://example.com" [] []
  8. (*
  9. "https://example.com/"
  10. *)
  11. crossOrigin
  12. "https://example.com:8042"
  13. [ "over"; "there" ]
  14. [ str "name" "ferret" ]
  15. (*
  16. "https://example.com:8042/over/there?name=ferret"
  17. *)
  1. custom // Root -> string list -> QueryParameter list -> Option<string> -> string
  2. // sample
  3. custom Absolute
  4. [ "packages"; "elmish"; "elmish"; "latest"; "String" ]
  5. []
  6. (Some "length")
  7. (*
  8. "/packages/elmish/elmish/latest/String#length"
  9. *)
  10. custom Relative [ "there" ] [ str "name" "ferret" ] None
  11. (*
  12. "there?name=ferret"
  13. *)
  14. custom
  15. (CrossOrigin "https://example.com:8042")
  16. [ "over"; "there" ]
  17. [ str "name" "ferret" ]
  18. (Some "nose")
  19. (*
  20. "https://example.com:8042/over/there?name=ferret#nose"
  21. *)