Hiyudev / turls

🐒 A simple JavaScript utility for conditionally query string together.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Turls

🐒 A simple JavaScript utility for conditionally query string together.



About β€’ Getting started β€’ Authors β€’ Acknowledgements β€’ License


🧐 About

Turls is a simple, JavaScript utility for conditionally query string together. The idea behind Turls is to prevent developers from rewriting the same code in multiple places, while also making it easy to dynamically construct advanced queries that can be easily shared across multiple files.

Turls is perfect for applications that need to dynamically query an API or database, but it can also be used as a general purpose URL builder.

🏁 Getting Started

  1. Install with npm, yarn or pnpm:
npm install turls
yarn add turls
pnpm add turls
  1. Use the library:
// ESM
import turls from 'turls';
turls("https://api.example.com/", "query", {
  "id=1": true,
  "name=John Doe": true,
  "age=30": true
})
// => "https://api.example.com/query?id=1&name=John%20Doe&age=30"

// CommonJS
const turls = require('turls');
turls("https://api.example.com/", "query", {
  "id=1": true,
  "name=John Doe": true,
  "age=30": true
})
// => "https://api.example.com/query?id=1&name=John%20Doe&age=30"

πŸš€ Usage

turls("https://api.example.com/", "query");
// => "https://api.example.com/query"

turls("https://api.example.com/", "query", "search");
// => "https://api.example.com/querysearch"

turls("https://api.example.com/", "query", {
  "id=1": true,
  "name=John Doe": true,
  "age=30": true
})
// => "https://api.example.com/query?id=1&name=John%20Doe&age=30"

turls("https://api.example.com/", "query", {
  "id=1": true,
  "name=John Doe": true,
  "age=30": false
})
// => "https://api.example.com/query?id=1&name=John%20Doe"

turls("https://api.example.com/", "query", {
  "id=1": false,
  "name=John Doe": true,
  "age=30": false,
})
// => "https://api.example.com/query?name=John%20Doe"

✍️ Authors

πŸŽ‰ Acknowledgements

Β© License

  • MIT License

About

🐒 A simple JavaScript utility for conditionally query string together.

License:MIT License


Languages

Language:TypeScript 86.2%Language:JavaScript 13.8%