medialize / medialize/URI.js

add method for case-insensitive query parameter existence check

Open
#294 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Requires More Interest
Dominant language
JavaScript
Stars
6.2k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

While according to RFC spec, query params are case-sensitive, there should be a method allowing for case-insensitive search for query params when just checking for existence.

var uri = "http://www.acme.com?test=1"
uri.hasQuery("TEST"); //returns false

New function signature would look like this:

URI.hasQueryParameter = function (data, name, caseSensitive) {
    //force undefined params
    var param3, param4;
    return URI.hasQuery(data, name, param3, param4, caseSensitive);
}

...with new param to main hasQuery method:

URI.hasQuery = function (data, name, value, withinArray, caseSensitive) {
// SNIP...
        switch (getType(value)) {
            case 'Undefined':
                // true if exists (but may be empty)
                return !caseSensitive ? name in data : return data[name] !== undefined;
// SNIP...
}
uri.hasQueryParameter("TEST", false); //returns true
uri.hasQueryParameter("TEST", true); //returns false

This approach maintains backwards compatibility without ugly calls from client script.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the URI.hasQuery implementation and the existing query-parameter API described in the issue. Verify how existence checks currently handle undefined values, then make the requested case-insensitive behavior and backward compatibility observable through the examples in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.