-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfdnextApi.js
More file actions
72 lines (60 loc) · 1.83 KB
/
fdnextApi.js
File metadata and controls
72 lines (60 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { createEngine } from '@itxtech/fdnext-core';
import { createExternalLinkPreviewProcessor } from '@/services/fdnextExternalLinkPreview';
import { summaryText } from '@/services/fdnextResultView';
import store from '@/store';
let engine;
function getEngine() {
if (!engine) {
const processor = createExternalLinkPreviewProcessor();
engine = createEngine({
processors: [processor].filter(Boolean)
});
}
return engine;
}
function currentLang() {
return store.getLang();
}
function limitOption(limit) {
const value = Number(limit);
return Number.isFinite(value) && value > 0 ? { limit: value } : {};
}
function controllerGroupOption() {
return { controllerGroup: store.getControllerGroupParam() };
}
export const getEmbeddedInfo = () => {
const capabilities = getEngine().getCapabilities({ lang: currentLang() });
return {
...capabilities,
server: {
...capabilities.server,
name: 'Embedded iTXTech fdnext'
}
};
};
export const decodeEmbeddedPartNumber = pn => getEngine().decodePart({
query: pn,
lang: currentLang(),
...controllerGroupOption()
});
export const searchEmbeddedPartNumber = (pn, limit = 0) => getEngine().searchParts({
query: pn,
lang: currentLang(),
...controllerGroupOption(),
...limitOption(limit)
});
export const summarizeEmbeddedPartNumber = pn => summaryText(decodeEmbeddedPartNumber(pn));
export const decodeEmbeddedFlashId = id => getEngine().decodeIdentifier({
query: id,
lang: currentLang(),
idScheme: 'nand.flash_id',
...controllerGroupOption()
});
export const searchEmbeddedFlashId = (id, limit = 0) => getEngine().searchIdentifiers({
query: id,
lang: currentLang(),
idScheme: 'nand.flash_id',
...controllerGroupOption(),
...limitOption(limit)
});
export const summarizeEmbeddedFlashId = id => summaryText(decodeEmbeddedFlashId(id));