MCPcopy Create free account
hub / github.com/apitable/apitable / parseAllUrl

Function parseAllUrl

packages/core/src/utils/string.ts:123–168  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

121}
122
123export function parseAllUrl(value: string): ISegment[] {
124 const valueArray: ISegment[] = [];
125 let lastEndIndex = 0;
126
127 const regExp = new RegExp(LINK_REG);
128 let execResult = regExp.exec(value);
129
130 if (execResult == null) {
131 return [{
132 type: SegmentType.Text,
133 text: value,
134 }];
135 }
136
137 while (execResult) {
138 const startIndex = execResult.index;
139 const regExpMatch = execResult[0]!;
140
141 if (startIndex !== lastEndIndex) {
142 valueArray.push({
143 type: SegmentType.Text,
144 text: value.substring(lastEndIndex, startIndex),
145 });
146 }
147
148 if (hasUrlProtocol(regExpMatch)) {
149 valueArray.push({ type: SegmentType.Url, link: regExpMatch, text: regExpMatch });
150 } else if (isUrl(regExpMatch)) {
151 valueArray.push({ type: SegmentType.Url, link: `http://${regExpMatch}`, text: regExpMatch });
152 } else if (isEmailUrl(regExpMatch)) {
153 valueArray.push({ type: SegmentType.Url, link: `mailto:${regExpMatch}`, text: regExpMatch });
154 }
155
156 lastEndIndex = regExp.lastIndex;
157 execResult = regExp.exec(value);
158 }
159
160 if (lastEndIndex < value.length) {
161 valueArray.push({
162 type: SegmentType.Text,
163 text: value.substring(lastEndIndex),
164 });
165 }
166
167 return valueArray;
168}
169
170export const stringHash2Number = (str: string, range: number): number => {
171 /**

Callers

nothing calls this directly

Calls 5

hasUrlProtocolFunction · 0.85
isUrlFunction · 0.85
isEmailUrlFunction · 0.85
execMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected