@vdegenne/links 1.4.4 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +35 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -10,6 +10,13 @@ export type GoogleImagesSize = 'l' | 'm' | 'i' | 'qsvga' | 'vga' | 'svga' | 'xga
|
|
|
10
10
|
export type GoogleImagesDate = 'd' | 'w' | 'm' | 'y';
|
|
11
11
|
export declare function googleImagesUrl(input: string, size?: GoogleImagesSize, date?: GoogleImagesDate, excludeWords?: string[]): string;
|
|
12
12
|
export declare function googleImagesOpen(input: string, size?: GoogleImagesSize, date?: GoogleImagesDate, excludeWords?: string[]): void;
|
|
13
|
+
export interface GoogleImagesSearchContext {
|
|
14
|
+
query: string[];
|
|
15
|
+
excluded: string[];
|
|
16
|
+
size?: string;
|
|
17
|
+
date?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function googleImagesUrlAnalyzer(gImgUrl: string): GoogleImagesSearchContext;
|
|
13
20
|
export declare function googleTranslateUrl(input: string, lang?: string, source?: string): string;
|
|
14
21
|
export declare function googleTranslateOpen(input: string, lang?: string, source?: string): void;
|
|
15
22
|
export declare function youtubeUrl(input: string): string;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH;;GAEG;AAEH,MAAM,MAAM,gBAAgB,GACzB,GAAG,GACH,GAAG,GACH,GAAG,GACH,OAAO,GACP,KAAK,GACL,MAAM,GACN,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,MAAM,GACN,MAAM,GACN,MAAM,GACN,MAAM,GACN,MAAM,GACN,MAAM,CAAC;AAEV,MAAM,M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gB,QAAQ,CAAC,KAAK,EAAE,MAAM,UAErC;AACD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,QAEtC;AAGD,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,UAKnC;AACD,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,QAEpC;AAGD,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,UAEtC;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,QAEvC;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,UAExC;AACD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,QAEzC;AAGD,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,UAIpC;AACD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,QAErC"}
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export function googleImagesUrl(input, size, date, excludeWords) {
|
|
|
15
15
|
const base = new URL('http://www.google.com/search');
|
|
16
16
|
let params = new URLSearchParams();
|
|
17
17
|
params.append('tbm', 'isch');
|
|
18
|
-
params.append('as_q',
|
|
18
|
+
params.append('as_q', input);
|
|
19
19
|
if (excludeWords && excludeWords.length) {
|
|
20
20
|
params.append('as_eq', excludeWords.join(' '));
|
|
21
21
|
}
|
|
@@ -41,6 +41,40 @@ export function googleImagesUrl(input, size, date, excludeWords) {
|
|
|
41
41
|
export function googleImagesOpen(input, size, date, excludeWords) {
|
|
42
42
|
open(googleImagesUrl(input, size, date, excludeWords));
|
|
43
43
|
}
|
|
44
|
+
export function googleImagesUrlAnalyzer(gImgUrl) {
|
|
45
|
+
const url = new URL(gImgUrl);
|
|
46
|
+
const info = { query: [], excluded: [] };
|
|
47
|
+
const params = url.searchParams;
|
|
48
|
+
if (!params.get('tbm') || params.get('tbm') !== 'isch') {
|
|
49
|
+
throw new Error('Not a Google Images search');
|
|
50
|
+
}
|
|
51
|
+
const getKeywords = (paramName) => (params.get(paramName) || '').split(' ').filter((v) => v);
|
|
52
|
+
const keywords = [
|
|
53
|
+
...getKeywords('q'),
|
|
54
|
+
...getKeywords('as_q'),
|
|
55
|
+
...getKeywords('as_eq'),
|
|
56
|
+
];
|
|
57
|
+
// Search keywords
|
|
58
|
+
info.query = keywords.filter((v) => !v.startsWith('-'));
|
|
59
|
+
// Excluded search keywords
|
|
60
|
+
info.excluded = keywords
|
|
61
|
+
.filter((v) => v.startsWith('-'))
|
|
62
|
+
.map((v) => v.slice(1));
|
|
63
|
+
const tbs = params.get('tbs');
|
|
64
|
+
if (tbs) {
|
|
65
|
+
const tbsInfo = Object.fromEntries(tbs.split(',').map((p) => p.split(':')));
|
|
66
|
+
if (tbsInfo.isz) {
|
|
67
|
+
info.size =
|
|
68
|
+
tbsInfo.isz === 'lt' && tbsInfo.islt
|
|
69
|
+
? tbsInfo.islt
|
|
70
|
+
: tbsInfo.isz;
|
|
71
|
+
}
|
|
72
|
+
if (tbsInfo.qdr) {
|
|
73
|
+
info.date = tbsInfo.qdr;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return info;
|
|
77
|
+
}
|
|
44
78
|
// google translate
|
|
45
79
|
export function googleTranslateUrl(input, lang = 'en', source = 'auto') {
|
|
46
80
|
return `https://translate.google.com/?sl=${source}&tl=${lang}&text=${encodeURIComponent(input)}&op=translate`;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,SAAS,IAAI,CAAC,GAAW,EAAE,MAAM,GAAG,IAAI;IACvC,IAAI,MAAM,EAAE;QACX,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;KAC3B;SAAM;QACN,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACjB;AACF,CAAC;AA2BD,MAAM,UAAU,eAAe,CAC9B,KAAa,EACb,IAAuB,EACvB,IAAuB,EACvB,Y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,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;AAChE,CAAC;AACD,MAAM,UAAU,YAAY,CAAC,KAAa;IACzC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED,OAAO;AACP,MAAM,UAAU,OAAO,CAAC,KAAa;IACpC,OAAO,sEAAsE,kBAAkB,CAC9F,KAAK,CACL,EAAE,CAAC;AACL,CAAC;AACD,MAAM,UAAU,QAAQ,CAAC,KAAa;IACrC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AACtB,CAAC","sourcesContent":["/**\n * @license\n * Copyright (c) 2023 Valentin Degenne\n * SPDX-License-Identifier: MIT\n */\n\nfunction open(url: string, newTab = true) {\n\tif (newTab) {\n\t\twindow.open(url, '_blank');\n\t} else {\n\t\twindow.open(url);\n\t}\n}\n\n/**\n * Google related links\n */\n// google images\nexport type GoogleImagesSize =\n\t| 'l'\n\t| 'm'\n\t| 'i'\n\t| 'qsvga'\n\t| 'vga'\n\t| 'svga'\n\t| 'xga'\n\t| '2mp'\n\t| '4mp'\n\t| '6mp'\n\t| '8mp'\n\t| '10mp'\n\t| '12mp'\n\t| '15mp'\n\t| '20mp'\n\t| '40mp'\n\t| '70mp';\n\nexport type GoogleImagesDate = 'd' | 'w' | 'm' | 'y';\n\nexport function googleImagesUrl(\n\tinput: string,\n\tsize?: GoogleImagesSize,\n\tdate?: GoogleImagesDate,\n\texcludeWords?: string[],\n) {\n\tconst base = new URL('http://www.google.com/search');\n\tlet params = new URLSearchParams();\n\tparams.append('tbm', 'isch');\n\tparams.append('as_q', input);\n\tif (excludeWords && excludeWords.length) {\n\t\tparams.append('as_eq', excludeWords.join(' '));\n\t}\n\n\tlet tbsParams = [];\n\tif (size) {\n\t\tif (!['s', 'm', 'l'].includes(size)) {\n\t\t\ttbsParams.push('isz:lt');\n\t\t\ttbsParams.push(`islt:${size}`);\n\t\t} else {\n\t\t\ttbsParams.push(`isz:${size}`);\n\t\t}\n\t}\n\tif (date) {\n\t\ttbsParams.push(`qdr:${date}`);\n\t}\n\tif (tbsParams.length > 0) {\n\t\tparams.append('tbs', tbsParams.join(','));\n\t}\n\n\tbase.search = params.toString();\n\treturn base.toString();\n}\n\nexport function googleImagesOpen(\n\tinput: string,\n\tsize?: GoogleImagesSize,\n\tdate?: GoogleImagesDate,\n\texcludeWords?: string[],\n) {\n\topen(googleImagesUrl(input, size, date, excludeWords));\n}\n\nexport interface GoogleImagesSearchContext {\n\tquery: string[];\n\texcluded: string[];\n\tsize?: string;\n\tdate?: string;\n}\n\nexport function googleImagesUrlAnalyzer(\n\tgImgUrl: string,\n): GoogleImagesSearchContext {\n\tconst url = new URL(gImgUrl);\n\tconst info: GoogleImagesSearchContext = {query: [], excluded: []};\n\tconst params = url.searchParams;\n\tif (!params.get('tbm') || params.get('tbm') !== 'isch') {\n\t\tthrow new Error('Not a Google Images search');\n\t}\n\tconst getKeywords = (paramName: string) =>\n\t\t(params.get(paramName) || '').split(' ').filter((v) => v);\n\tconst keywords = [\n\t\t...getKeywords('q'),\n\t\t...getKeywords('as_q'),\n\t\t...getKeywords('as_eq'),\n\t];\n\n\t// Search keywords\n\tinfo.query = keywords.filter((v) => !v.startsWith('-'));\n\t// Excluded search keywords\n\tinfo.excluded = keywords\n\t\t.filter((v) => v.startsWith('-'))\n\t\t.map((v) => v.slice(1));\n\n\tconst tbs = params.get('tbs');\n\tif (tbs) {\n\t\tconst tbsInfo = Object.fromEntries(\n\t\t\ttbs.split(',').map((p) => p.split(':')),\n\t\t);\n\t\tif (tbsInfo.isz) {\n\t\t\tinfo.size =\n\t\t\t\ttbsInfo.isz === 'lt' && tbsInfo.islt\n\t\t\t\t\t? tbsInfo.islt\n\t\t\t\t\t: tbsInfo.isz;\n\t\t}\n\t\tif (tbsInfo.qdr) {\n\t\t\tinfo.date = tbsInfo.qdr;\n\t\t}\n\t}\n\treturn info;\n}\n\n// google translate\nexport function googleTranslateUrl(\n\tinput: string,\n\tlang = 'en',\n\tsource = 'auto',\n) {\n\treturn `https://translate.google.com/?sl=${source}&tl=${lang}&text=${encodeURIComponent(\n\t\tinput,\n\t)}&op=translate`;\n}\nexport function googleTranslateOpen(\n\tinput: string,\n\tlang?: string,\n\tsource?: string,\n) {\n\topen(googleTranslateUrl(input, lang, source));\n}\nexport function youtubeUrl(input: string) {\n\treturn `https://www.youtube.com/results?search_query=${encodeURIComponent(\n\t\tinput,\n\t)}`;\n}\nexport function youtubeOpen(input: string) {\n\topen(youtubeUrl(input));\n}\n\n/**\n * Japanese related\n */\n// jisho\nexport function jishoUrl(input: string) {\n\treturn `https://jisho.org/search/${encodeURIComponent(input)}`;\n}\nexport function jishoOpen(input: string) {\n\topen(jishoUrl(input));\n}\n\n// goo\nexport function gooUrl(input: string) {\n\t// return `https://dictionary.goo.ne.jp/word/${encodeURIComponent(word)}/`;\n\treturn `https://dictionary.goo.ne.jp/srch/all/${encodeURIComponent(\n\t\tinput,\n\t)}/m0u/`;\n}\nexport function gooOpen(input: string) {\n\topen(gooUrl(input));\n}\n\n// weblio\nexport function weblioUrl(input: string) {\n\treturn `https://www.weblio.jp/content/${encodeURIComponent(input)}`;\n}\nexport function weblioOpen(input: string) {\n\topen(weblioUrl(input));\n}\n\n// kotobank\nexport function kotobankUrl(input: string) {\n\treturn `https://kotobank.jp/word/${encodeURIComponent(input)}`;\n}\nexport function kotobankOpen(input: string) {\n\topen(kotobankUrl(input));\n}\n\n// Mdbg\nexport function mdbgUrl(input: string) {\n\treturn `https://www.mdbg.net/chinese/dictionary?page=worddict&wdrst=0&wdqb=${encodeURIComponent(\n\t\tinput,\n\t)}`;\n}\nexport function mdbgOpen(input: string) {\n\topen(mdbgUrl(input));\n}\n"]}
|