Skip to content
/ turls Public

🐢 A simple JavaScript utility for conditionally query string together.

License

Notifications You must be signed in to change notification settings

Hiyudev/turls

Repository files navigation

Turls

🐢 A simple JavaScript utility for conditionally query string together.



AboutGetting startedAuthorsAcknowledgementsLicense


🧐 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.

Topics

Resources

License

Stars

Watchers

Forks