mirror of
https://github.com/gnh1201/welsonjs.git
synced 2026-04-18 18:18:42 +00:00
Add input validation to search(): require keyword be a non-empty string and throw a TypeError if not. Normalize limit to a finite integer between 1 and 100 (default 10) using Math.floor and Math.min/Math.max to prevent invalid or out-of-range values.
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
// coupang.js
|
|
// Coupang SERP API Client
|
|
// Copyright 2019-2025, Namhyeon Go <gnh1201@catswords.re.kr> and the WelsonJS contributors.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// https://github.com/gnh1201/welsonjs
|
|
//
|
|
var HTTP = require("lib/http");
|
|
|
|
function search(keyword, limit) {
|
|
if (typeof keyword !== "string" || keyword.length === 0) {
|
|
throw new TypeError("keyword must be a non-empty string");
|
|
}
|
|
|
|
limit = Math.min(100, Math.max(1,
|
|
Math.floor((typeof limit === "number" && isFinite(limit)) ? limit : 10)
|
|
));
|
|
|
|
return HTTP.create()
|
|
.setParameters({
|
|
"keyword": keyword,
|
|
"limit": limit
|
|
})
|
|
.setDataType("json")
|
|
.open("GET", "https://cold-math-31f3.gnh1201.workers.dev/api/v1/products/search")
|
|
.send()
|
|
.responseBody
|
|
;
|
|
}
|
|
|
|
exports.search = search;
|
|
|
|
exports.VERSIONINFO = "Coupang SERP API Client (coupang.js) version 1.0";
|
|
exports.AUTHOR = "gnh1201@catswords.re.kr";
|
|
exports.global = global;
|
|
exports.require = global.require;
|