本文整理汇总了TypeScript中lodash.sortedUniq函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sortedUniq函数的具体用法?TypeScript sortedUniq怎么用?TypeScript sortedUniq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sortedUniq函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: mergeSeriesByTime
/**
* Collect all unique timestamps from series list and use it to fill
* missing points by null.
*/
function mergeSeriesByTime(seriesList) {
let timestamps = [];
for (let i = 0; i < seriesList.length; i++) {
const seriesPoints = seriesList[i].datapoints;
for (let j = 0; j < seriesPoints.length; j++) {
timestamps.push(seriesPoints[j][POINT_TIME_INDEX]);
}
}
timestamps = sortedUniq(timestamps.sort());
for (let i = 0; i < seriesList.length; i++) {
const seriesPoints = seriesList[i].datapoints;
const seriesTimestamps = seriesPoints.map(p => p[POINT_TIME_INDEX]);
const extendedSeries = [];
let pointIndex;
for (let j = 0; j < timestamps.length; j++) {
pointIndex = sortedIndexOf(seriesTimestamps, timestamps[j]);
if (pointIndex !== -1) {
extendedSeries.push(seriesPoints[pointIndex]);
} else {
extendedSeries.push([null, timestamps[j]]);
}
}
seriesList[i].datapoints = extendedSeries;
}
return seriesList;
}
开发者ID:ArcticSnowman,项目名称:grafana,代码行数:31,代码来源:file_export.ts
示例2: main
async function main() {
const commonTypes: string[] = [];
const tsconfigPath = path.join("..", "tsconfig.json");
const tsconfigFile = await readFile(tsconfigPath);
lineBreak = _.find(["\r\n", "\n", "\r"], x => tsconfigFile.includes(x)) || "\n";
// Read each function definition and fp-ify it
const subfolders = ["common"];
const promises: Array<Promise<string[]>> = [];
for (const subfolder of subfolders) {
promises.push(new Promise<string[]>((resolve, reject) => {
fs.readdir(path.join("..", subfolder), (err, files) => {
if (err) {
console.error(`failed to list directory contents for '${subfolder}': `, err);
reject(err);
return;
}
const filePaths = files.map(f => path.join("..", subfolder, f));
try {
resolve(processDefinitions(filePaths, commonTypes));
} catch (e) {
console.error(`failed to process files in '${subfolder}': `, e);
reject(e);
}
});
}));
}
let functionNames: string[];
try {
functionNames = _.flatten(await Promise.all(promises));
} catch (err) {
console.error("Failed to parse all functions: ", err);
return;
}
functionNames = _.sortedUniq(_.sortBy(functionNames, _.toLower));
const fpFile = [
"// AUTO-GENERATED: do not modify this file directly.",
"// If you need to make changes, modify generate-fp.ts (if necessary), then open a terminal in types/lodash/scripts, and do:",
"// npm run fp",
"",
...functionNames.map(f => `import ${f} = require("./fp/${f}");`),
"",
"export = _;",
"",
"declare const _: _.LoDashFp;",
"declare namespace _ {",
" interface LoDashFp {",
...functionNames.map(f => ` ${f}: typeof ${f};`),
" }",
"}",
"",
"// Backward compatibility with --target es5",
"declare global {",
" // tslint:disable-next-line:no-empty-interface",
" interface Set<T> { }",
" // tslint:disable-next-line:no-empty-interface",
" interface Map<K, V> { }",
" // tslint:disable-next-line:no-empty-interface",
" interface WeakSet<T> { }",
" // tslint:disable-next-line:no-empty-interface",
" interface WeakMap<K extends object, V> { }",
"}",
"",
].join(lineBreak);
fs.writeFile(path.join("..", "fp.d.ts"), fpFile, (err) => {
if (err)
console.error("Failed to write fp.d.ts: ", err);
});
// Make sure the generated files are listed in tsconfig.json, so they are included in the lint checks
const tsconfig = tsconfigFile.split(lineBreak).filter(row => !row.includes("fp/") || row.includes("fp/convert.d.ts"));
const newRows = functionNames.map(f => ` "fp/${f}.d.ts",`);
newRows[newRows.length - 1] = newRows[newRows.length - 1].replace(",", "");
const insertIndex = _.findLastIndex(tsconfig, row => row.trim() === "]"); // Assume "files" is the last array
if (!tsconfig[insertIndex - 1].endsWith(","))
tsconfig[insertIndex - 1] += ",";
tsconfig.splice(insertIndex, 0, ...newRows);
fs.writeFile(tsconfigPath, tsconfig.join(lineBreak), (err) => {
if (err)
console.error(`Failed to write ${tsconfigPath}: `, err);
});
}
开发者ID:Q-Man,项目名称:DefinitelyTyped,代码行数:85,代码来源:generate-fp.ts
示例3: buildFiles
private static buildFiles(
files: models.IFileCollection,
hasDefaultLightFile: boolean,
) {
const sts = constants.iconsManifest;
return sortedUniq(
sortBy(
files.supported.filter(x => !x.disabled && x.icon),
item => item.icon,
),
).reduce(
(old, current) => {
const defs = old.defs;
const names = old.names;
const languageIds = old.languageIds;
const light = old.light;
const icon = current.icon;
const hasLightVersion = current.light;
const iconFileType = `${sts.fileTypePrefix}${icon}`;
const iconFileLightType = `${sts.fileTypeLightPrefix}${icon}`;
const iconFileExtension = Utils.fileFormatToString(current.format);
const filename = `${
hasLightVersion ? iconFileLightType : iconFileType
}${sts.iconSuffix}${iconFileExtension}`;
const fileIconPath = this.getIconPath(filename);
const filePath = Utils.pathUnixJoin(fileIconPath, iconFileType);
const fileLightPath = Utils.pathUnixJoin(
fileIconPath,
iconFileLightType,
);
const iconFileDefinition = `${sts.definitionFilePrefix}${icon}`;
const iconFileLightDefinition = `${
sts.definitionFileLightPrefix
}${icon}`;
const isFilename = current.filename;
defs[iconFileDefinition] = {
iconPath: `${filePath}${sts.iconSuffix}${iconFileExtension}`,
};
if (hasDefaultLightFile && !hasLightVersion) {
defs[iconFileLightDefinition] = {
iconPath: `${filePath}${sts.iconSuffix}${iconFileExtension}`,
};
}
if (hasLightVersion) {
defs[iconFileLightDefinition] = {
iconPath: `${fileLightPath}${sts.iconSuffix}${iconFileExtension}`,
};
}
if (current.languages) {
const assignLanguages = langId => {
languageIds[langId] = iconFileDefinition;
};
const assignLanguagesLight = langId => {
light.languageIds[langId] = hasLightVersion
? iconFileLightDefinition
: iconFileDefinition;
};
current.languages.forEach(langIds => {
if (Array.isArray(langIds.ids)) {
langIds.ids.forEach(id => {
assignLanguages(id);
assignLanguagesLight(id);
});
} else {
assignLanguages(langIds.ids);
assignLanguagesLight(langIds.ids);
}
});
}
const populateFn = (extension: string) => {
if (isFilename) {
names.fileNames[extension] = iconFileDefinition;
light.fileNames[extension] = hasLightVersion
? iconFileLightDefinition
: iconFileDefinition;
} else {
const noDotExtension = Utils.removeFirstDot(extension);
names.fileExtensions[noDotExtension] = iconFileDefinition;
light.fileExtensions[noDotExtension] = hasLightVersion
? iconFileLightDefinition
: iconFileDefinition;
}
};
current.extensions.forEach(populateFn);
const hasGlobDefinitions =
current.filenamesGlob &&
!!current.filenamesGlob.length &&
current.extensionsGlob &&
!!current.extensionsGlob.length;
if (hasGlobDefinitions) {
Utils.combine(current.filenamesGlob, current.extensionsGlob).forEach(
//.........这里部分代码省略.........
开发者ID:robertohuertasm,项目名称:vscode-icons,代码行数:101,代码来源:manifestBuilder.ts
注:本文中的lodash.sortedUniq函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论