Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quick-tigers-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@jabascript/query": major
---

Rename `getLiteralValue` to `getValueLiteral`.
4 changes: 2 additions & 2 deletions packages/query/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function parseSearchParams(searchParams, allowFalsy = false) {
const result = {};

for (const [x, y] of searchParams.entries()) {
const val = getLiteralValue(y);
const val = getValueLiteral(y);
const isArray = x.endsWith("[]") || x in result;

if (!isArray && !allowFalsy && (val === undefined || val === null)) continue;
Expand All @@ -154,7 +154,7 @@ export function parseSearchParams(searchParams, allowFalsy = false) {
* @param {string} value
* @returns {string | null | undefined}
*/
export function getLiteralValue(value) {
export function getValueLiteral(value) {
if (value === "null") return null;
if (value === "undefined") return undefined;
return value;
Comment on lines +157 to 160
Expand Down
16 changes: 8 additions & 8 deletions packages/query/tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";

import { createSearchParams, createURL, getLiteralValue, parseSearchParams } from "../src/index.js";
import { createSearchParams, createURL, getValueLiteral, parseSearchParams } from "../src/index.js";

describe("createSearchParams", () => {
it("should create basic search params", () => {
Expand Down Expand Up @@ -276,19 +276,19 @@ describe("parseSearchParams", () => {
});
});

describe("getLiteralValue", () => {
describe("getValueLiteral", () => {
it("should convert the string 'null' to null", () => {
expect(getLiteralValue("null")).toBeNull();
expect(getValueLiteral("null")).toBeNull();
});

it("should convert the string 'undefined' to undefined", () => {
expect(getLiteralValue("undefined")).toBeUndefined();
expect(getValueLiteral("undefined")).toBeUndefined();
});

it("should return any other string unchanged", () => {
expect(getLiteralValue("hello")).toBe("hello");
expect(getLiteralValue("")).toBe("");
expect(getLiteralValue("0")).toBe("0");
expect(getLiteralValue("false")).toBe("false");
expect(getValueLiteral("hello")).toBe("hello");
expect(getValueLiteral("")).toBe("");
expect(getValueLiteral("0")).toBe("0");
expect(getValueLiteral("false")).toBe("false");
});
});
Loading