Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hangul-search

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hangul-search - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

2

package.json
{
"name": "hangul-search",
"version": "1.0.0",
"version": "1.1.0",
"description": "Json객체에서 한글 검색을 수행. 한글 초성 검색을 지원. Korean search within JSON objects. Supports Korean initial consonant search.",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -59,2 +59,4 @@ ## hansearch

/* 출력 결과
{
"items" :
[

@@ -67,2 +69,3 @@ {

]
}
*/

@@ -98,2 +101,4 @@ ```

/* 출력 결과
{
"items" :
[

@@ -106,2 +111,3 @@ {

]
}
*/

@@ -121,2 +127,9 @@ </script>

.mark() 메소드 체이닝을 지원합니다. 일치한 검색어를 `<mark>` 태그로 감싸주며, 원하는 태그를 인자로 넘겨줄 수 있습니다.
```js
var result = hansearch(json, "ㅈ렬화").mark(); // 검색어와 일치한 단어를 <mark> 태그로 감싼 결과를 리턴합니다.
var result = hansearch(json, "ㅈ렬화").mark("tags"); // 검색어와 일치한 단어를 <tags> 태그로 감싼 결과를 리턴합니다.
```
## References

@@ -123,0 +136,0 @@

@@ -11,11 +11,17 @@ /**

* const result = hansearch(jsonArray, "키워드", ["key1", "key2"]); // jsonArray의 key1 및 key2 값만 탐색
* const result = hansearch(jsonArray, "키워드").mark(); // 결과 값 <mark></mark> 태그 치환
**/
interface MarkedResult {
results: Record<string, any>[];
mark: (tag?: string) => Record<string, any>[];
}
declare module 'hansearch' {
const hansearch: (
jsonObj: Record<string, any>[],
keyWord: string,
options?: string[]
) => Record<string, any>[];
jsonObj: Record<string, any>[],
keyWord: string,
options?: string[]
) => MarkedResult;
export = hansearch;
}
}

@@ -31,7 +31,6 @@ /*!

const regex = CHO_HANGUL.reduce((acc, cho, index) => acc.replace(new RegExp(cho, "g"), `[${combineHangul(index, 0, 0)}-${combineHangul(index + 1, 0, -1)}]`), escapedSearch);
return new RegExp(`(${regex})`, "i");
return new RegExp(`(${regex})`, "ig");
};
// keys에 지정된 키값을 대상으로 검색 수행. keys가 빈 배열이면 모든 키를 대상으로 검색 수행.
return function (jsonObj, keyWord, keys = []) {
const hansearch = function (jsonObj, keyWord, keys = []) {
const regex = makeRegexByCho(keyWord);

@@ -48,4 +47,29 @@ let searchResult = jsonObj.filter((obj) => {

});
return searchResult;
return {
items: searchResult,
mark: function (tag = "mark") {
return {
items: searchResult.map((obj) => {
const markedObj = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (keys.length === 0 || keys.includes(key)) {
if (Array.isArray(obj[key])) {
// 배열인 경우 각 원소에 대해 처리
markedObj[key] = obj[key].map((item) => item.replace(regex, `<${tag}>$&</${tag}>`));
} else {
markedObj[key] = obj[key].replace(regex, `<${tag}>$&</${tag}>`);
}
} else markedObj[key] = obj[key];
}
}
return markedObj;
}),
};
},
};
};
});
return hansearch;
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc