node.url.pas 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. {
  2. This file is part of the Pas2JS run time library.
  3. Copyright (c) 2020 by Michael Van Canneyt
  4. NodeJS url module import.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit node.url;
  12. {$mode objfpc}
  13. {$ModeSwitch externalclass}
  14. interface
  15. uses
  16. Types, JS, nodeJS;
  17. Type
  18. TNJSURLSearchParams = Class external name 'URLSearchParams' (TJSObject)
  19. constructor new; overload;
  20. constructor new(aQueryString : string);overload;
  21. constructor new(aObject : TJSObject);overload;
  22. constructor new(aMap : TJSMap);overload;
  23. constructor new(aArray : TJSArray);overload;
  24. procedure append(const aName, aValue : string);
  25. procedure delete(const aName : string);
  26. function entries : TJSIterator;
  27. function get(const aName : string) : string;
  28. function getAll(const aName : string) : TStringDynArray;
  29. function has(const aName : string) : boolean;
  30. function keys : TJSIterator;
  31. procedure set_(const aName, aValue : string); external name 'set';
  32. procedure sort;
  33. function toString : string;
  34. function values: TJSIterator;
  35. end;
  36. TNJSURL = Class external name 'URL' (TJSObject)
  37. Public
  38. hash : string;
  39. host : string;
  40. hostname : string;
  41. href : string;
  42. origin : string;
  43. password : string;
  44. pathname : string;
  45. port : string;
  46. protocol : string;
  47. search : String;
  48. searchParams : TNJSURLSearchParams;
  49. username : string;
  50. constructor new(aURL : string); overload;
  51. constructor new(aURL,aBase : string); overload;
  52. constructor new(aURL : string; aBase : TNJSURL); overload;
  53. function toString : string;
  54. function toJSON : string;
  55. end;
  56. TJNSURLGlobalFormatOptions = class external name 'Object' (TJSObject)
  57. auth : boolean;
  58. fragment : boolean;
  59. search : boolean;
  60. unicode : boolean;
  61. end;
  62. TJNSUrlGlobal = class external name 'Object' (TJSObject)
  63. class function domainToASCII(adomain : string) : string;
  64. class function domainToUnicode(adomain : string) : string;
  65. class function fileURLToPath(aURL : string) : string;
  66. class function format(aURL : TNJSURL; Options : TJSObject) : string;
  67. class function format(aURL : TNJSURL; Options : TJNSURLGlobalFormatOptions) : string;
  68. class function pathToFileURL(aPath : string) : TNJSURL;
  69. end;
  70. var
  71. url : TJNSUrlGlobal;
  72. implementation
  73. initialization
  74. url:=TJNSUrlGlobal(require('url'));
  75. end.