MCPcopy
hub / github.com/gaotianliuyun/gao / sortListByFirst

Function sortListByFirst

lib/sortName.js:146–178  ·  view source on GitHub ↗
(vodList,key)

Source from the content-addressed store, hash-verified

144
145// 首字母开头排序
146export const sortListByFirst = (vodList,key) => {
147 key = key||'vod_name';
148 // 名字以特殊符号开头的应用列表
149 const symbol_list = [];
150 // 名字以中文开头的应用列表
151 const cn_list = [];
152 // 名字以英文开头的应用列表
153 const en_list = [];
154 // 名字以数字开头的应用列表
155 const num_list = [];
156
157 vodList.forEach((vod) => {
158 const { vod_name } = vod;
159 //通过正则进行数据分类
160 if (/[\u4e00-\u9fa5]/.test(vod_name[0])) {
161 cn_list.push(vod);
162 } else if (/[a-zA-Z]/.test(vod_name[0])) {
163 en_list.push(vod);
164 } else if (/[\d]/.test(vod_name[0])) {
165 num_list.push(vod);
166 } else {
167 symbol_list.push(vod);
168 }
169 });
170 //按照要求的方式进行数据排序重组
171 const newList = [
172 ...cn_list.sort((a, b) => a.vod_name[0]?.localeCompare(b.vod_name[0])),
173 ...en_list.sort((a, b) => a.vod_name[0].localeCompare(b.vod_name[0])),//localeCompare可以不区分大小写的进行排序
174 ...num_list.sort((a, b) => a.vod_name[0] - b.vod_name[0]),
175 ...symbol_list.sort((a, b) => a.vod_name[0] - b.vod_name[0])
176 ];
177 return newList
178};

Callers

nothing calls this directly

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected