code stringlengths 24 2.07M | docstring stringlengths 25 85.3k | func_name stringlengths 1 92 | language stringclasses 1
value | repo stringlengths 5 64 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
function dateFormatISO(dt) {
return dt.format('YYYY-MM-DDTHH:mm:ss[Z]');
} | Formats a moment() object to: YYYY-MM-DDTHH:mm:ssZ
Example: 2017-07-13T13:31:13Z
@param {Object} dt The moment object to export.
@return {string} YYYY-MM-DDTHH:mm:ssZ. | dateFormatISO | javascript | google/WebFundamentals | gulp-tasks/wfHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js | Apache-2.0 |
function dateFormatISOShort(dt) {
return dt.format('YYYY-MM-DD');
} | Formats a moment() object to: YYYY-MM-DD
Example: 2017-07-13
@param {Object} dt The moment object to export.
@return {string} YYYY-MM-DD. | dateFormatISOShort | javascript | google/WebFundamentals | gulp-tasks/wfHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js | Apache-2.0 |
function dateFormatPretty(dt) {
return dt.format('dddd, MMMM Do YYYY');
} | Formats a moment() object to: dddd, MMMM Do YYYY
Example: Friday, July 13th 2017
@param {Object} dt The moment object to export.
@return {string} dddd, MMMM Do YYYY. | dateFormatPretty | javascript | google/WebFundamentals | gulp-tasks/wfHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js | Apache-2.0 |
function dateFormatRSS(dt) {
return dt.format('DD MMM YYYY HH:mm:ss [GMT]');
} | Formats a moment() object to: DD MMM YYYY HH:mm:ss GMT
Example: 13 Jul 2017 13:31:13 GMT
@param {Object} dt The moment object to export.
@return {string} DD MMM YYYY HH:mm:ss GMT. | dateFormatRSS | javascript | google/WebFundamentals | gulp-tasks/wfHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js | Apache-2.0 |
function getMatch(regEx, content, defaultResponse) {
const result = content.match(regEx);
if (result && result[1]) {
return result[1];
}
return defaultResponse;
} | Gets the first regEx match on a string
@param {RegEx} regEx The regex to test.
@param {string} content The content to search.
@param {string} [defaultResponse] The default response to provide.
@return {string} The regex match. | getMatch | javascript | google/WebFundamentals | gulp-tasks/wfRegEx.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfRegEx.js | Apache-2.0 |
function getMatches(regEx, content) {
let results = [];
let myArray;
while ((myArray = regEx.exec(content)) !== null) {
results.push(myArray);
}
return results;
} | Gets all of the regEx match on a string
@param {RegEx} regEx The regex to test.
@param {string} content The content to search.
@return {Array} The regex matches. | getMatches | javascript | google/WebFundamentals | gulp-tasks/wfRegEx.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfRegEx.js | Apache-2.0 |
function renderTemplate(templateFile, context, outputFile) {
const ts = fs.readFileSync(templateFile, 'utf8');
const template = Handlebars.compile(ts);
const result = template(context);
mkdirp.sync(path.dirname(outputFile));
fs.writeFileSync(outputFile, result);
} | Renders a template
@param {string} templateFile The path to the template.
@param {Object} context The data to render into the template.
@param {string} outputFile The path to the rendered file. | renderTemplate | javascript | google/WebFundamentals | gulp-tasks/wfTemplateHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfTemplateHelper.js | Apache-2.0 |
function getFullFeedEntries(articles, maxItems, includeContent = true) {
let yamlCont = fs.readFileSync('./src/data/_contributors.yaml', 'utf8');
let contributors = jsYaml.safeLoad(yamlCont);
articles = articles.slice(0, maxItems);
articles.forEach(function(article) {
let content = fs.readFileSync(article.f... | Gets the full article to use in feeds
@param {Array} articles List of files to get content.
@param {number} maxItems Number of items to include in the feed.
@param {boolean=} includeContent Whether to include article body content in
the feed. True by default.
@return {Array} list of articles | getFullFeedEntries | javascript | google/WebFundamentals | gulp-tasks/wfTemplateHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfTemplateHelper.js | Apache-2.0 |
function generateFeeds(files, options) {
if (!global.WF.options.buildRSS) {
return;
}
if (!files || files.length === 0) {
return;
}
gutil.log(' ', `Generating '${options.title}' RSS & ATOM feeds...`);
const maxItems = options.maxItems || global.WF.maxArticlesInFeed;
let context = {
title: opti... | Generate the RSS & ATOM feeds for a list of files
@param {Array} files List of files to generate feed items for
@param {Object} options Options used to generate the feed | generateFeeds | javascript | google/WebFundamentals | gulp-tasks/wfTemplateHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfTemplateHelper.js | Apache-2.0 |
function generatePodcastFeed(files, options) {
gutil.log(' ', 'Generating podcast feed for', options.title);
let context = {
title: options.title,
subtitle: options.subtitle,
summary: options.summary,
author: options.author,
image: options.image,
articles: files,
host: 'https://developer... | Generate feeds for a podcast
@param {Array} files List of files to generate feed items for
@param {Object} options Options used to generate the feed | generatePodcastFeed | javascript | google/WebFundamentals | gulp-tasks/wfTemplateHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfTemplateHelper.js | Apache-2.0 |
function _generateListPage(files, options) {
let context = {
title: options.title,
section: options.section,
articles: files,
};
let template = path.join(global.WF.src.templates, 'article-list.md');
if (options.template) {
template = options.template;
}
let outputFile = options.outputFile;
... | Generate a list page
@private
@param {Array} files List of files to generate page for
@param {Object} options Options used to generate the page | _generateListPage | javascript | google/WebFundamentals | gulp-tasks/wfTemplateHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfTemplateHelper.js | Apache-2.0 |
function generateListPage(files, options) {
gutil.log(' ', 'Generating article list page for', options.title);
_generateListPage(files, options);
} | Generate a list page
@param {Array} files List of files to generate page for
@param {Object} options Options used to generate the page | generateListPage | javascript | google/WebFundamentals | gulp-tasks/wfTemplateHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfTemplateHelper.js | Apache-2.0 |
function generateTOCbyMonth(files, options) {
gutil.log(' ', 'Generating _toc.yaml for', options.title);
let context = {
year: options.year,
title: options.title,
section: options.section,
months: wfHelper.splitByMonth(files).reverse(),
};
const template = path.join(global.WF.src.templates, 'toc... | Generate a TOC page by month
@param {Array} files List of files to generate page for
@param {Object} options Options used to generate the page | generateTOCbyMonth | javascript | google/WebFundamentals | gulp-tasks/wfTemplateHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfTemplateHelper.js | Apache-2.0 |
function generateIndex(files, options) {
gutil.log(' ', 'Generating index page...');
let context = {
description: options.description,
section: options.section,
articles: files,
};
if (options.title) {
context.title = options.title;
}
let template = path.join(global.WF.src.templates, 'index.... | Generate an index page
@param {Array} files List of files to generate page for
@param {Object} options Options used to generate the page | generateIndex | javascript | google/WebFundamentals | gulp-tasks/wfTemplateHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfTemplateHelper.js | Apache-2.0 |
function generateLatestWidget(files, options) {
gutil.log(' ', 'Generating latest updates widget...');
// Create a new array instead of mutating the existing array
const articles = [];
const len = options.articlesToShow || files.length;
for (let i = 0; i < len; i++) {
articles.push(files[i]);
}
const ... | Generate the latest updates widget
@param {Array} files List of files
@param {Object} options Options used to generate the widget | generateLatestWidget | javascript | google/WebFundamentals | gulp-tasks/wfTemplateHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfTemplateHelper.js | Apache-2.0 |
function generateTagPages(files, options) {
gutil.log(' ', 'Generating tag pages for ' + options.section + '...');
let allTags = {};
files.forEach(function(file) {
const tags = file.tags;
tags.forEach(function(tag) {
tag = tag.toLowerCase();
if (!allTags[tag]) {
allTags[tag] = {
... | Generate the tag pages
@param {Array} files List of files
@param {Object} options Options used to generate the widget | generateTagPages | javascript | google/WebFundamentals | gulp-tasks/wfTemplateHelper.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfTemplateHelper.js | Apache-2.0 |
async function getChangedFiles() {
const cmd = `git diff --name-only --cached`;
const results = await wfHelper.promisedExec(cmd, '.');
return results.split('\n');
} | Gets the list of files that have been staged.
@return {Promise<Array<String>>} Returns array of changed Files. | getChangedFiles | javascript | google/WebFundamentals | gulp-tasks/wfUpdatedOn.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfUpdatedOn.js | Apache-2.0 |
function getYouTubeAPIKey() {
try {
let apiKey = process.env.YOUTUBE_API_KEY;
if (!apiKey) {
apiKey = fs.readFileSync('./src/data/youtubeAPIKey.txt', 'utf8');
}
return apiKey.trim();
} catch (ex) {
gutil.log(' ', 'youtubeAPIKey not found.');
}
return null;
} | Gets the YouTube API key.
@return {string} YouTubeAPI key, or null. | getYouTubeAPIKey | javascript | google/WebFundamentals | gulp-tasks/wfYouTubeShows.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfYouTubeShows.js | Apache-2.0 |
function generateFeed(file, context, options = {}) {
const baseOutputPath = path.join(global.WF.src.content, 'shows');
const outputFile = options.outputPath ?
path.join(options.outputPath, file) : path.join(baseOutputPath, file);
const template = path.join(global.WF.src.templates, file);
wfTemplateHelper.re... | Renders the RSS or ATOM template based on the context.
@param {string} file File to generate.
@param {!Object} context Context to use when rendering.
@param {!Object} options Options used to generate the feed | generateFeed | javascript | google/WebFundamentals | gulp-tasks/wfYouTubeShows.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfYouTubeShows.js | Apache-2.0 |
async function getVideos(buildType, allVideos = false) {
const apiKey = getYouTubeAPIKey();
if (!apiKey) {
const msg = `${chalk.cyan('getVideos')} failed,`;
// If the build type is production, abort with critical failure.
if (buildType === 'production') {
gutil.log(' ', chalk.red('ERROR:'), msg, '... | Gets the Data feed from YouTube.
@param {string} buildType If build type is production, and it can read the
API key, the function will fail.
@param {boolean=} allVideos If true, returns all videos in the playlist.
Default: false.
@return {Promise<Array>} Array of videos. | getVideos | javascript | google/WebFundamentals | gulp-tasks/wfYouTubeShows.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfYouTubeShows.js | Apache-2.0 |
function videosByYear(videos) {
const result = {};
videos.forEach((video) => {
const publishedAtMoment = moment(video.snippet.publishedAt);
const year = publishedAtMoment.year();
if (!result[year]) {
result[year] = [];
}
result[year].push(video);
});
return result;
} | Splits a list of videos by year published.
@param {!Array} videos The array of videos to split.
@return {!Object} A list of videos split by year. | videosByYear | javascript | google/WebFundamentals | gulp-tasks/wfYouTubeShows.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfYouTubeShows.js | Apache-2.0 |
async function getAllVideosByYear(buildType) {
return videosByYear(await getVideos(buildType, true));
} | @param {string} buildType If build type is production, and it can read the
API key, the function will fail.
@return {!Promise<!Object>} Promise that resolves to an object of videos by
year. | getAllVideosByYear | javascript | google/WebFundamentals | gulp-tasks/wfYouTubeShows.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfYouTubeShows.js | Apache-2.0 |
function buildFeeds(videos, options) {
if (!global.WF.options.buildRSS) {
return;
}
const articles = [];
videos.forEach((video) => {
const iframe = `
<iframe width="560" height="315" frameborder="0" allowfullscreen
src="https://www.youtube.com/embed/${video.snippet.resourceId.videoId}">
... | Builds the RSS & ATOM feeds from a YouTube video feed.
@param {!Array} videos Array of videos from YouTube.
@param {!Object=} options Options used to generate the feed | buildFeeds | javascript | google/WebFundamentals | gulp-tasks/wfYouTubeShows.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfYouTubeShows.js | Apache-2.0 |
canFindJSDocConf = (jsdocConfPath) => {
try {
fs.accessSync(jsdocConfPath, fs.F_OK);
return true;
} catch (err) {
gutil.log(gutil.colors.red(
`Unable to find jsdoc Config File @ '${jsdocConfPath}'`
));
gutil.log(err);
return false;
}
} | Helper method that checks the JSDoc config file exists.
@param {string} jsdocConfPath
@return {Promise} | canFindJSDocConf | javascript | google/WebFundamentals | gulp-tasks/reference-docs/build-js-docs.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/build-js-docs.js | Apache-2.0 |
canFindJSDocConf = (jsdocConfPath) => {
try {
fs.accessSync(jsdocConfPath, fs.F_OK);
return true;
} catch (err) {
gutil.log(gutil.colors.red(
`Unable to find jsdoc Config File @ '${jsdocConfPath}'`
));
gutil.log(err);
return false;
}
} | Helper method that checks the JSDoc config file exists.
@param {string} jsdocConfPath
@return {Promise} | canFindJSDocConf | javascript | google/WebFundamentals | gulp-tasks/reference-docs/build-js-docs.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/build-js-docs.js | Apache-2.0 |
buildJSDocs = (tag, srcCodePath, docOutputPath, jsdocConfPath) => {
// Make sure the JSDoc conf exists
if (!canFindJSDocConf(jsdocConfPath)) {
return;
}
// Make sure the JSDoc conf has the "webFundamentals" values
const jsdocConfigContents = fs.readFileSync(jsdocConfPath);
const jsdocConfig = JSON.pars... | Build Devsite friend JSDocs.
@param {string} tag Tag name of the update
@param {string} srcCodePath Path of source code to generate docs for.
@param {string} docOutputPath Where the docs should be written to.
@param {string} jsdocConfPath Path of the JSDoc config file.
@return {Promise} | buildJSDocs | javascript | google/WebFundamentals | gulp-tasks/reference-docs/build-js-docs.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/build-js-docs.js | Apache-2.0 |
buildJSDocs = (tag, srcCodePath, docOutputPath, jsdocConfPath) => {
// Make sure the JSDoc conf exists
if (!canFindJSDocConf(jsdocConfPath)) {
return;
}
// Make sure the JSDoc conf has the "webFundamentals" values
const jsdocConfigContents = fs.readFileSync(jsdocConfPath);
const jsdocConfig = JSON.pars... | Build Devsite friend JSDocs.
@param {string} tag Tag name of the update
@param {string} srcCodePath Path of source code to generate docs for.
@param {string} docOutputPath Where the docs should be written to.
@param {string} jsdocConfPath Path of the JSDoc config file.
@return {Promise} | buildJSDocs | javascript | google/WebFundamentals | gulp-tasks/reference-docs/build-js-docs.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/build-js-docs.js | Apache-2.0 |
buildReferenceDocsForTags = async (
latestTags, gitUrl, docPath, jsdocConfPath) => {
for (const [folder, tag] of Object.entries(latestTags)) {
const taggedOutputPath = path.join(docPath, folder);
// If this tag is for an older version, and a folder for that version
// already exists on the file syste... | Given a set of tags - Loop through each one and build the docs if needed.
@param {Object} latestTags And object mapping folder names to release tags.
The object keys will be major verions (e.g. `v4`) or either `latest`
or `prerelease`.
@param {string} gitUrl The URL of the Git repo to get tags from.
@param {st... | buildReferenceDocsForTags | javascript | google/WebFundamentals | gulp-tasks/reference-docs/build-reference-docs.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/build-reference-docs.js | Apache-2.0 |
buildReferenceDocsForTags = async (
latestTags, gitUrl, docPath, jsdocConfPath) => {
for (const [folder, tag] of Object.entries(latestTags)) {
const taggedOutputPath = path.join(docPath, folder);
// If this tag is for an older version, and a folder for that version
// already exists on the file syste... | Given a set of tags - Loop through each one and build the docs if needed.
@param {Object} latestTags And object mapping folder names to release tags.
The object keys will be major verions (e.g. `v4`) or either `latest`
or `prerelease`.
@param {string} gitUrl The URL of the Git repo to get tags from.
@param {st... | buildReferenceDocsForTags | javascript | google/WebFundamentals | gulp-tasks/reference-docs/build-reference-docs.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/build-reference-docs.js | Apache-2.0 |
buildReferenceDocs = async (gitUrl, docPath, jsdocConfPath) => {
const latestTags = await getLatestTags(gitUrl);
await buildReferenceDocsForTags(
latestTags, gitUrl, docPath, jsdocConfPath, 'latest');
} | Build the reference docs for a project.
@param {string} gitUrl The Github URL.
@param {string} docPath Path to place the documentation files (i.e. built
JSDocs)
@param {string} jsdocConfPath Path to the JSDoc config path/ | buildReferenceDocs | javascript | google/WebFundamentals | gulp-tasks/reference-docs/build-reference-docs.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/build-reference-docs.js | Apache-2.0 |
buildReferenceDocs = async (gitUrl, docPath, jsdocConfPath) => {
const latestTags = await getLatestTags(gitUrl);
await buildReferenceDocsForTags(
latestTags, gitUrl, docPath, jsdocConfPath, 'latest');
} | Build the reference docs for a project.
@param {string} gitUrl The Github URL.
@param {string} docPath Path to place the documentation files (i.e. built
JSDocs)
@param {string} jsdocConfPath Path to the JSDoc config path/ | buildReferenceDocs | javascript | google/WebFundamentals | gulp-tasks/reference-docs/build-reference-docs.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/build-reference-docs.js | Apache-2.0 |
getLatestTags = async (gitUrl, oldestMajorVersion = 1) => {
const latestTagsMap = {};
// Don't fetch the tag map if we've already fetched it.
if (!remoteTags) {
remoteTags = await remoteGitTags(gitUrl);
}
const sortedTags = [...remoteTags.keys()].sort(semver.rcompare);
for (const tag of sortedTags) {
... | Gets the latest tags for each major version of a git repo. The object
returned will also include keys for `latest` as well as `prerelease`,
if applicable.
@param {string} gitUrl URL of the git repo you want to get tags for.
@param {number} [oldestMajorVersion=1] The oldest major version to include.
@return {Promise<Ob... | getLatestTags | javascript | google/WebFundamentals | gulp-tasks/reference-docs/get-latest-tags.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/get-latest-tags.js | Apache-2.0 |
getLatestTags = async (gitUrl, oldestMajorVersion = 1) => {
const latestTagsMap = {};
// Don't fetch the tag map if we've already fetched it.
if (!remoteTags) {
remoteTags = await remoteGitTags(gitUrl);
}
const sortedTags = [...remoteTags.keys()].sort(semver.rcompare);
for (const tag of sortedTags) {
... | Gets the latest tags for each major version of a git repo. The object
returned will also include keys for `latest` as well as `prerelease`,
if applicable.
@param {string} gitUrl URL of the git repo you want to get tags for.
@param {number} [oldestMajorVersion=1] The oldest major version to include.
@return {Promise<Ob... | getLatestTags | javascript | google/WebFundamentals | gulp-tasks/reference-docs/get-latest-tags.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/get-latest-tags.js | Apache-2.0 |
getSourceCode = (gitUrl, tag, outPath) => {
fs.ensureDirSync(outPath);
const args = [
'clone',
'--branch', tag,
'--depth', '1',
'--config', 'advice.detachedHead=false',
gitUrl,
outPath,
];
return wfHelper.promisedExec(`git ${args.join(' ')}`);
} | Get the source code from a tag from a git repo.
@param {string} gitUrl URL to git repo.
@param {string} tag The tag to get.
@param {string} outPath Path to write the source code to | getSourceCode | javascript | google/WebFundamentals | gulp-tasks/reference-docs/get-source-code.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/get-source-code.js | Apache-2.0 |
getSourceCode = (gitUrl, tag, outPath) => {
fs.ensureDirSync(outPath);
const args = [
'clone',
'--branch', tag,
'--depth', '1',
'--config', 'advice.detachedHead=false',
gitUrl,
outPath,
];
return wfHelper.promisedExec(`git ${args.join(' ')}`);
} | Get the source code from a tag from a git repo.
@param {string} gitUrl URL to git repo.
@param {string} tag The tag to get.
@param {string} outPath Path to write the source code to | getSourceCode | javascript | google/WebFundamentals | gulp-tasks/reference-docs/get-source-code.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/reference-docs/get-source-code.js | Apache-2.0 |
function wfHeadingsAtLeast(ast, file, minLevel) {
if (!minLevel || minLevel <= 1 || minLevel > 6) {
return;
}
visit(ast, 'heading', function(node) {
if (generated(node)) {
return;
}
if (node.depth >= minLevel) {
return false;
}
const msg = `First heading level should be at leas... | Remark Lint Test - minimum heading level.
@param {Node} ast - Root node.
@param {File} file - Virtual file.
@param {number} minLevel | wfHeadingsAtLeast | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-headings.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-headings.js | Apache-2.0 |
function wfHeadingsInMarkdown(ast, file, setting) {
let msg = 'Headings must use markdown style, HTML is not permitted.';
visit(ast, 'html', function(node) {
if (reHeading.test(node.value)) {
file.message(msg, node);
}
});
} | Remark Lint Test - flags HTML style heading tags.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfHeadingsInMarkdown | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-headings.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-headings.js | Apache-2.0 |
function wfHeadingsBlank(ast, file, setting) {
visit(ast, 'heading', function(node) {
let title = toString(node).trim();
if (title.length === 0) {
file.message('Headings cannot be empty.', node);
}
});
} | Remark Lint Test - flags empty headings.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfHeadingsBlank | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-headings.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-headings.js | Apache-2.0 |
function wfNoMarkupInTitle(ast, file, setting) {
visit(ast, 'heading', function(node) {
if (node.depth !== 1) {
return;
}
node.children.forEach((child) => {
if (validHeadingTypes.indexOf(child.type) === -1) {
let msg = 'Top level headings must only contain text.';
file.message(... | Remark Lint Test - verifies there is no markup in level 1 headings.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfNoMarkupInTitle | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-headings.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-headings.js | Apache-2.0 |
function wfTLDR(ast, file, setting) {
const msgLevel = 'TL;DR headings must be level 3 or greater.';
const msgHide = 'TL;DR headings must be hidden from the TOC with ' +
' `{: .hide-from-toc }`';
visit(ast, 'heading', function(node) {
let body = toString(node);
if (reTLDR.test(body)) {
if (nod... | Remark Lint Test - verifies TL;DRs are at least L3 & hidden from the TOC.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfTLDR | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-headings.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-headings.js | Apache-2.0 |
function wfLineBreakInLink(ast, file, setting) {
const msg = 'Link contains unescaped whitespace or accidental line break.';
const RE_WHITESPACE = /\s/;
visit(ast, 'html', function(node) {
const anchorTag = node.value.match(/<a((.|\n)*?)>/i);
if (anchorTag && anchorTag[1]) {
const href = anchorTag[1... | Remark Lint Test - check if links have whitespace or line breaks.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfLineBreakInLink | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-html.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-html.js | Apache-2.0 |
function wfYouTube(ast, file, setting) {
let msg = 'YouTube videos must use DevSite embed.';
visit(ast, 'html', function(node) {
if (reYouTube.test(node.value)) {
file.message(msg, node);
}
});
} | Remark Lint Test - flags iframes that embed YouTube content.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfYouTube | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-html.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-html.js | Apache-2.0 |
function wfHTMLDGCLinks(ast, file, setting) {
let msg = 'Do not hard code `developers.google.com` in links.';
visit(ast, 'html', function(node) {
if (reDGCLink.test(node.value)) {
file.message(msg, node);
}
});
} | Remark Lint Test - flags hard coded developers.google.com links.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfHTMLDGCLinks | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-html.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-html.js | Apache-2.0 |
function wfInternalLinks(ast, file, setting) {
let msg = 'Do not use internal Google sandboxed links';
visit(ast, 'html', function(node) {
if (reSandboxedLink.test(node.value)) {
file.message(msg, node);
}
});
} | Remark Lint Test - flags *.sandbox.google.com links.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfInternalLinks | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-html.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-html.js | Apache-2.0 |
function wfUnsafeShortLinks(ast, file, setting) {
let msg = 'Do not use unsafe `HTTP://goo.gl/` links';
visit(ast, 'html', function(node) {
if (reGooGL.test(node.value)) {
file.message(msg, node);
}
});
} | Remark Lint Test - flags unsafe goo.gl short links.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfUnsafeShortLinks | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-html.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-html.js | Apache-2.0 |
function wfForcedLang(ast, file, setting) {
let msg = 'Hard coded language URL in link (`hl=xx`).';
visit(ast, 'html', function(node) {
let match = reHref.exec(node.value);
if (match && match[1]) {
let parsedUrl = url.parse(match[1]);
let queryString = parsedUrl.query;
if (queryString && q... | Remark Lint Test - flags hard coded language links (hl=xx).
@param {Object} ast
@param {Object} file
@param {Object} setting | wfForcedLang | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-html.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-html.js | Apache-2.0 |
function doesImageExist(file, imgPath, node) {
const msgHardCoded = 'Do not hard code `developers.google.com` in paths.';
// Is the image potentially on a remote server?
// - indicated by http:// or https://
if (reRemote.test(imgPath)) {
// Is it on our server?
if (imgPath.indexOf('developers.google.co... | Verifies that images exist and links are properly used.
@param {Object} file The source file that included the image
@param {Object} imgPath The URI to the image
@param {Object} node The Remark node
@return {null} Nothing | doesImageExist | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-images.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-images.js | Apache-2.0 |
function wfImagesInMD(ast, file, setting) {
visit(ast, 'image', function(node) {
if (node.url && node.url.trim().length > 0) {
doesImageExist(file, node.url, node);
}
});
} | Remark Lint Test - verifies markdown images files exist.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfImagesInMD | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-images.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-images.js | Apache-2.0 |
function wfImagesInHTML(ast, file, setting) {
visit(ast, 'html', function(node) {
let matched = reImgSrc.exec(node.value);
if (matched && matched[1]) {
doesImageExist(file, matched[1], node);
}
});
} | Remark Lint Test - verifies html image files exist.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfImagesInHTML | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-images.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-images.js | Apache-2.0 |
function wfLineBreakInLink(ast, file, setting) {
const msg = 'Link contains unescaped whitespace or accidental line break.';
const RE_WHITESPACE = /\n/;
visit(ast, 'link', function(node) {
let nodeUrl = node.url;
if (nodeUrl.indexOf('href=') >= 0) {
nodeUrl = nodeUrl.match(/href=['|"]((.|\n)*?)['|"]... | Remark Lint Test - check if links have whitespace or line breaks.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfLineBreakInLink | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-links.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-links.js | Apache-2.0 |
function wfForcedLang(ast, file, setting) {
let msg = 'Hard coded language URL in link (`hl=xx`)';
visit(ast, 'link', function(node) {
let parsedUrl = url.parse(node.url);
let queryString = parsedUrl.query;
if (queryString && queryString.toLowerCase().indexOf('hl=') >= 0) {
file.message(msg, node)... | Remark Lint Test - check if links have hard coded languages.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfForcedLang | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-links.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-links.js | Apache-2.0 |
function wfDGCLinks(ast, file, setting) {
let msg = 'Do not hard code `developers.google.com` in links.';
visit(ast, 'link', function(node) {
let parsedUrl = url.parse(node.url);
let hostname = parsedUrl.hostname;
if (hostname && hostname.toLowerCase() === 'developers.google.com') {
file.message(m... | Remark Lint Test - verifies links are not hard coded to d.g.c.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfDGCLinks | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-links.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-links.js | Apache-2.0 |
function wfUnsafeShort(ast, file, setting) {
let msg = 'Do not use unsafe `HTTP://goo.gl/` links';
visit(ast, 'link', function(node) {
let parsedUrl = url.parse(node.url);
let protocol = parsedUrl.protocol;
let hostname = parsedUrl.hostname;
if (hostname && hostname.toLowerCase() === 'goo.gl') {
... | Remark Lint Test - checks for unsecured shortlinks.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfUnsafeShort | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-links.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-links.js | Apache-2.0 |
function wfInternalLinks(ast, file, setting) {
let msg = 'Do not use internal Google sandboxed links.';
visit(ast, 'link', function(node) {
let parsedUrl = url.parse(node.url);
let hostname = parsedUrl.hostname;
if (hostname && hostname.toLowerCase() === 'sandbox.google.com') {
file.message(msg, n... | Remark Lint Test - checks for links to sandbox.google.com.
@param {Object} ast
@param {Object} file
@param {Object} setting | wfInternalLinks | javascript | google/WebFundamentals | gulp-tasks/remark-lint-tests/check-links.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/remark-lint-tests/check-links.js | Apache-2.0 |
function test(filename, project) {
return new Promise(function(resolve, reject) {
const results = [];
let validator = new JSONValidator();
validator.addSchema(LINK, LINK.id);
validator.addSchema(ATTRIBUTE, ATTRIBUTE.id);
validator.addSchema(TOC_ELEMENT, TOC_ELEMENT.id);
validator.addSchema(LOW... | Tests and validates a _project.yaml file.
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested.
@param {Object} project The parsed contents of the project file.
@return {Promise} A promise with the result of the test. | test | javascript | google/WebFundamentals | gulp-tasks/tests/bookYaml.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/bookYaml.js | Apache-2.0 |
function test(filename, tags) {
if (Array.isArray(tags) === true) {
return Promise.resolve(true);
}
return Promise.reject({
level: 'ERROR',
filename: filename,
message: `Common tags file must be an array, was ${typeof tags}`,
});
} | Tests and validates a commonTags.json file.
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested.
@param {Object} tags The parsed contents of the tags file.
@return {Promise} A promise with the result of the test. | test | javascript | google/WebFundamentals | gulp-tasks/tests/commonTagsJson.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/commonTagsJson.js | Apache-2.0 |
function getLineNumber(contents, idx) {
return testHelpers.getLineNumber(contents, idx);
} | Simple wrapper for testHelpers.getLineNumber.
@param {string} contents The content of the string to check.
@param {Number} idx Where in the string to stop.
@return {Number} The line number the index ends on. | getLineNumber | javascript | google/WebFundamentals | gulp-tasks/tests/commonTypos.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/commonTypos.js | Apache-2.0 |
function test(filename, contents, options) {
const results = [];
if (!options.commonTypos || options.skipTypos || options.ignoreTypos) {
return results;
}
/**
* Simple wrapper that adds a warning to the list
*
* @param {string} message The message to add.
* @param {object} position The line num... | Tests & validates the contents of an HTML or Markdown file.
@param {string} filename The name of the file to be tested
@param {string} contents The contents of the file to be tested
@param {Object} options The options object
@return {Array} An array of warnings and errors found in the file | test | javascript | google/WebFundamentals | gulp-tasks/tests/commonTypos.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/commonTypos.js | Apache-2.0 |
function logWarning(message, position) {
results.push({
level: 'WARNING',
filename: filename,
position: position,
message: message,
});
} | Simple wrapper that adds a warning to the list
@param {string} message The message to add.
@param {object} position The line number the warning occurred on. | logWarning | javascript | google/WebFundamentals | gulp-tasks/tests/commonTypos.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/commonTypos.js | Apache-2.0 |
function test(filename, contributors) {
return new Promise(function(resolve, reject) {
const results = [];
let validator = new JSONValidator();
validator.addSchema(SCHEMA_CONTRIBUTOR, SCHEMA_CONTRIBUTOR.id);
validator.validate(contributors, SCHEMA_CONTRIBUTORS)
.errors.forEach((err) => {
... | Tests and validates a contributors.yaml file.
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested.
@param {Object} contributors The parsed contents of the contributors file.
@return {Promise} A promise with the result of the test. | test | javascript | google/WebFundamentals | gulp-tasks/tests/contributorsYaml.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/contributorsYaml.js | Apache-2.0 |
function test(filename, glossary) {
return new Promise(function(resolve, reject) {
const results = [];
let validator = new JSONValidator();
validator.addSchema(SCHEMA_GLOSSARY_ITEM, SCHEMA_GLOSSARY_ITEM.id);
validator.addSchema(SCHEMA_GLOSSARY_LINK, SCHEMA_GLOSSARY_LINK.id);
validator.validate(glo... | Tests and validates a glossary.yaml file.
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested.
@param {Object} glossary The parsed contents of the glossary file.
@return {Promise} A promise with the result of the test. | test | javascript | google/WebFundamentals | gulp-tasks/tests/glossaryYaml.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/glossaryYaml.js | Apache-2.0 |
function getLineNumber(content, idx) {
const subStr = content.substring(0, idx);
const lineNum = subStr.split(/\r\n|\r|\n/).length;
return lineNum;
} | Gets the line number of the current string up to the index point
@param {string} content The content of the string to check
@param {Number} idx Where in the string to stop
@return {Number} The line number the index ends on | getLineNumber | javascript | google/WebFundamentals | gulp-tasks/tests/helpers.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/helpers.js | Apache-2.0 |
function doesFileExist(filename) {
if (!filename) {
return false;
}
filename = filename.trim();
filename = filename.replace(/^\/?web\/(.*)/, 'src/content/en/$1');
try {
fs.accessSync(filename, fs.R_OK);
return true;
} catch (ex) {
return false;
}
} | Checks if a file exists.
@param {string} filename The WebFundamentals file path.
@return {Boolean} True if it exists, false if not. | doesFileExist | javascript | google/WebFundamentals | gulp-tasks/tests/helpers.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/helpers.js | Apache-2.0 |
function isInclude(filename, contents) {
if (wfRegEx.RE_IS_INCLUDE.test(contents)) {
return true;
}
if (wfRegEx.RE_IS_MD_INCLUDE.test(contents)) {
return true;
}
// Do any of the directories or files start with an underscore
return filename.split(path.sep).some((item) => {
return item.startsWit... | Checks if a file is an include file.
@param {string} filename The WebFundamentals file path.
@param {string} contents The contents of the file
@return {Boolean} True if it is, false if not. | isInclude | javascript | google/WebFundamentals | gulp-tasks/tests/helpers.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/helpers.js | Apache-2.0 |
function isTranslation(filename, contents) {
return wfRegEx.RE_TRANSLATED_PATH.test(filename);
} | Checks if a file is a translated file.
@param {string} filename The WebFundamentals file path.
@param {string} contents The contents of the file
@return {Boolean} True if it is, false if not. | isTranslation | javascript | google/WebFundamentals | gulp-tasks/tests/helpers.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/helpers.js | Apache-2.0 |
function isDevSiteHTMLPage(filename, contents) {
// const RE_HTML_TAG = /<html.*?>/;
const RE_HTML_DEVSITE = /<html\s.*?devsite.*?>/;
return RE_HTML_DEVSITE.test(contents);
} | Checks if a file is a DevSite HTML page.
@param {string} filename The WebFundamentals file path.
@param {string} contents The contents of the file
@return {Boolean} True if it is, false if not. | isDevSiteHTMLPage | javascript | google/WebFundamentals | gulp-tasks/tests/helpers.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/helpers.js | Apache-2.0 |
function test(filename, esLintConfig, contents) {
return new Promise(function(resolve, reject) {
const eslinter = new ESlintEngine(esLintConfig);
const report = eslinter.executeOnText(contents);
if (!report || !report.results[0]) {
const result = {
level: 'ERROR',
filename: filename,... | Lints a gulp-task JavaScript file
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested.
@param {string} esLintConfig The parsed esLintConfig to use.
@param {string} contents The contents of the file to be tested.
@return {Promise} A promise that... | test | javascript | google/WebFundamentals | gulp-tasks/tests/lintJavaScript.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/lintJavaScript.js | Apache-2.0 |
function test(filename, project) {
return new Promise(function(resolve, reject) {
const results = [];
let validator = new JSONValidator();
validator.validate(project, SCHEMA_PROJECT).errors.forEach((err) => {
let msg = `${err.stack || err.message}`;
msg = msg.replace('{}', '(' + err.instance +... | Tests and validates a _project.yaml file.
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested.
@param {Object} project The parsed contents of the project file.
@return {Promise} A promise with the result of the test. | test | javascript | google/WebFundamentals | gulp-tasks/tests/projectYaml.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/projectYaml.js | Apache-2.0 |
function test(filename, redirects) {
return new Promise(function(resolve, reject) {
let fromPattern = path.dirname(filename).split('/').splice(3).join('/');
fromPattern = path.join('/', 'web', fromPattern, '/');
const schemaRedirectsItem = {
id: '/RedirectItem',
type: 'object',
propertie... | Tests and validates a _redirects.yaml file.
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested.
@param {Object} redirects The parsed contents of the redirects file.
@return {Promise} A promise with the result of the test. | test | javascript | google/WebFundamentals | gulp-tasks/tests/redirectsYaml.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/redirectsYaml.js | Apache-2.0 |
function test(filename, typosList) {
return new Promise(function(resolve, reject) {
const results = [];
const validator = new JSONValidator();
validator.addSchema(SCHEMA_TYPO_ITEM, SCHEMA_TYPO_ITEM.id);
validator.validate(typosList, SCHEMA_TYPOS).errors.forEach((err) => {
let msg = `${err.stack ... | Tests the common-typos.yaml file.
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested.
@param {Object} typosList The parsed contents of the redirects file.
@return {Promise} A promise with the result of the test. | test | javascript | google/WebFundamentals | gulp-tasks/tests/validateCommonTyposFile.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateCommonTyposFile.js | Apache-2.0 |
function getLineNumber(contents, idx) {
return testHelpers.getLineNumber(contents, idx);
} | Simple wrapper for testHelpers.getLineNumber.
@param {string} contents The content of the string to check.
@param {Number} idx Where in the string to stop.
@return {Number} The line number the index ends on. | getLineNumber | javascript | google/WebFundamentals | gulp-tasks/tests/validateContent.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateContent.js | Apache-2.0 |
function doesFileExist(filename) {
return testHelpers.doesFileExist(filename);
} | Simple wrapper for testHelpers.doesFileExist.
@param {string} filename The WebFundamentals file path.
@return {Boolean} True if it exists, false if not. | doesFileExist | javascript | google/WebFundamentals | gulp-tasks/tests/validateContent.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateContent.js | Apache-2.0 |
function test(filename, contents, options) {
let matches;
const results = [];
const isLighthouse = wfRegEx.RE_LIGHTHOUSE_PATH.test(filename);
const isWorkbox = wfRegEx.RE_WORKBOX_PATH.test(filename);
const isSiteKit = wfRegEx.RE_SITEKIT_PATH.test(filename);
const isTranslation = testHelpers.isTranslation(f... | Tests & validates the contents of an HTML or Markdown file.
@param {string} filename The name of the file to be tested
@param {string} contents The contents of the file to be tested
@param {Object} options The options object
@return {Array} An array of warnings and errors found in the file | test | javascript | google/WebFundamentals | gulp-tasks/tests/validateContent.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateContent.js | Apache-2.0 |
function logError(message, position) {
results.push({
level: 'ERROR',
filename: filename,
position: position,
message: message,
});
} | Simple wrapper that adds an error to the list
@param {string} message The message to add.
@param {object} position The line number the error occurred on. | logError | javascript | google/WebFundamentals | gulp-tasks/tests/validateContent.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateContent.js | Apache-2.0 |
function logWarning(message, position) {
results.push({
level: 'WARNING',
filename: filename,
position: position,
message: message,
});
} | Simple wrapper that adds a warning to the list
@param {string} message The message to add.
@param {object} position The line number the warning occured on. | logWarning | javascript | google/WebFundamentals | gulp-tasks/tests/validateContent.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateContent.js | Apache-2.0 |
function test(filename) {
let isLegal = true;
ILLEGAL_CHARACTERS.forEach((char) => {
if (filename.indexOf(char) >= 0) {
isLegal = false;
}
});
return isLegal;
} | Tests a JSON file
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested
@param {string} contents The contents of the file to be tested
@return {Promise} A promise that resolves with TRUE if the file was tested
or FALSE if the file was not tested... | test | javascript | google/WebFundamentals | gulp-tasks/tests/validateFilename.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateFilename.js | Apache-2.0 |
function test(filename, contents) {
const filenameObj = path.parse(filename.toLowerCase());
const result = {
level: 'WARNING',
filename: filename,
message: 'No tests found for file type, was not tested.',
};
if (PERMITTED_NOT_TESTED_EXTENSIONS.indexOf(filenameObj.ext) >= 0) {
return Promise.reje... | Tests a JSON file
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested
@param {string} contents The contents of the file to be tested
@return {Promise} A promise that resolves with TRUE if the file was tested
or FALSE if the file was not tested... | test | javascript | google/WebFundamentals | gulp-tasks/tests/validateGeneric.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateGeneric.js | Apache-2.0 |
function getMetaTags(contents) {
const results = {};
const matched = wfRegEx.getMatches(/<meta .*?>/g, contents);
matched.forEach((match) => {
const key = wfRegEx.getMatch(/name=["'](.*?)["']/, match[0]);
if (key) {
results[key] = wfRegEx.getMatch(/value=["'](.*?)["']/, match[0]);
}
});
retu... | Reads all <meta> tags and pulls the name & value into an object
@param {string} contents The contents of the file
@return {Object} An object containing the meta tags | getMetaTags | javascript | google/WebFundamentals | gulp-tasks/tests/validateHtml.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateHtml.js | Apache-2.0 |
function test(filename, contents, options) {
if (filename.indexOf('/_code/') >= 0) {
return Promise.resolve(true);
}
const results = validateContent.test(filename, contents, options);
/**
* Simple wrapper that adds an error to the list
*
* @param {string} message The message to add.
* @param {... | Tests & validates an HTML file.
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested
@param {string} contents The contents of the file to be tested
@param {Object} options The options object
@return {Promise} A promise that resolves with TRUE if... | test | javascript | google/WebFundamentals | gulp-tasks/tests/validateHtml.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateHtml.js | Apache-2.0 |
function logError(message, position) {
results.push({
level: 'ERROR',
filename: filename,
position: position,
message: message,
});
} | Simple wrapper that adds an error to the list
@param {string} message The message to add.
@param {object} position The line number the error occurred on. | logError | javascript | google/WebFundamentals | gulp-tasks/tests/validateHtml.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateHtml.js | Apache-2.0 |
function logWarning(message, position) {
results.push({
level: 'WARNING',
filename: filename,
position: position,
message: message,
});
} | Simple wrapper that adds a warning to the list
@param {string} message The message to add.
@param {object} position The line number the warning occured on. | logWarning | javascript | google/WebFundamentals | gulp-tasks/tests/validateHtml.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateHtml.js | Apache-2.0 |
function test(filename, contents) {
if (filename.indexOf('/_code/') > 0) {
return Promise.resolve(true);
}
const result = {
level: 'WARNING',
filename: filename,
message: 'JavaScript files are generally not allowed.',
};
return Promise.reject([result]);
} | Tests & validates a JavaScript file.
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested
@param {string} contents The contents of the file to be tested
@return {Promise} A promise that resolves with TRUE if the file was tested
or FALSE if the ... | test | javascript | google/WebFundamentals | gulp-tasks/tests/validateJavaScript.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateJavaScript.js | Apache-2.0 |
function test(filename, contents) {
try {
const parsed = JSON.parse(contents);
return Promise.resolve(parsed);
} catch (ex) {
const result = {
level: 'ERROR',
filename: filename,
message: `Unable to parse JSON: ${ex.message}`,
};
return Promise.reject([result]);
}
} | Tests a JSON file
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested
@param {string} contents The contents of the file to be tested
@return {Promise} A promise that resolves with TRUE if the file was tested
or FALSE if the file was not tested... | test | javascript | google/WebFundamentals | gulp-tasks/tests/validateJson.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateJson.js | Apache-2.0 |
function doesFileExist(filename) {
return testHelpers.doesFileExist(filename);
} | Simple wrapper for testHelpers.doesFileExist.
@param {string} filename The WebFundamentals file path.
@return {Boolean} True if it exists, false if not. | doesFileExist | javascript | google/WebFundamentals | gulp-tasks/tests/validateMarkdown.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateMarkdown.js | Apache-2.0 |
function getLineNumber(contents, idx) {
return testHelpers.getLineNumber(contents, idx);
} | Simple wrapper for testHelpers.getLineNumber.
@param {string} contents The content of the string to check.
@param {Number} idx Where in the string to stop.
@return {Number} The line number the index ends on. | getLineNumber | javascript | google/WebFundamentals | gulp-tasks/tests/validateMarkdown.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateMarkdown.js | Apache-2.0 |
function test(filename, contents, options) {
return new Promise(function(resolve, reject) {
const results = validateContent.test(filename, contents, options);
/**
* Simple wrapper that adds an error to the list
*
* @param {string} message The message to add.
* @param {object} position The... | Tests a Markdown file
@param {string} filename The name of the file to be tested.
@param {string} contents The contents of the file to be tested.
@param {Object} options The options object
@return {Promise} Resolves to true if no errors, else an array of errors. | test | javascript | google/WebFundamentals | gulp-tasks/tests/validateMarkdown.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateMarkdown.js | Apache-2.0 |
function logError(message, position) {
results.push({
level: 'ERROR',
filename: filename,
position: position,
message: message,
});
} | Simple wrapper that adds an error to the list
@param {string} message The message to add.
@param {object} position The line number the error occurred on. | logError | javascript | google/WebFundamentals | gulp-tasks/tests/validateMarkdown.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateMarkdown.js | Apache-2.0 |
function logWarning(message, position) {
results.push({
level: 'WARNING',
filename: filename,
position: position,
message: message,
});
} | Simple wrapper that adds a warning to the list
@param {string} message The message to add.
@param {object} position The line number the warning occured on. | logWarning | javascript | google/WebFundamentals | gulp-tasks/tests/validateMarkdown.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateMarkdown.js | Apache-2.0 |
function test(filename, warnOnly) {
try {
// Read the file size and check if it exceeds the known limits
const stats = fs.statSync(filename);
const fileSize = Math.round(parseInt(stats.size, 10) / 1024);
const result = {
filename: filename,
};
if (fileSize > MAX_FILE_SIZE_ERROR && !warnO... | Tests & validates a JavaScript file.
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested
@param {boolean} warnOnly Only warn, never throw an error.
@return {Promise} A promise that resolves with TRUE if the file was tested
or FALSE if the file... | test | javascript | google/WebFundamentals | gulp-tasks/tests/validateMedia.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateMedia.js | Apache-2.0 |
function test(filename) {
try {
const stats = fs.statSync(filename);
const mode = stats.mode || 0;
if ((mode & 0o0001) || (mode & 0o0010) || (mode & 0o0100)) {
return false;
}
} catch (ex) {
// Unable to get stats for file, ignore this result.
}
return true;
} | Checks the permissions on a file to ensure no -x- executable files.
@param {string} filename The name of the file to be tested
@return {boolean} TRUE if the file is OK, FALSE if it has bad permissions. | test | javascript | google/WebFundamentals | gulp-tasks/tests/validatePermissions.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validatePermissions.js | Apache-2.0 |
function test(filename, contents) {
try {
const parsed = jsYaml.safeLoad(contents);
return Promise.resolve(parsed);
} catch (ex) {
const position = ex.mark;
const result = {
level: 'ERROR',
filename: filename,
message: ex.reason || `Unable to parse YAML`,
position: position,
... | Tests a YAML file
Note: The returned promise always resolves, it will never reject.
@param {string} filename The name of the file to be tested
@param {string} contents The contents of the file to be tested
@return {Promise<Object>} Parsed YAML object, or if it failed, an array
of errors. | test | javascript | google/WebFundamentals | gulp-tasks/tests/validateYaml.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/tests/validateYaml.js | Apache-2.0 |
function updateWorkboxBuild() {
return wfHelper.promisedExec(`npm install --save-dev workbox-build`);
} | We need to ensure workbox-build is up to date to get the latest
CDN version.
@return {Promise} Resolves once workbox has been updates | updateWorkboxBuild | javascript | google/WebFundamentals | gulp-tasks/workbox/workbox-generate-includes.js | https://github.com/google/WebFundamentals/blob/master/gulp-tasks/workbox/workbox-generate-includes.js | Apache-2.0 |
function deleteFile(filePath) {
if (!DELETE_ORPHANED) {
console.log(chalk.red('ORPHANED'), filePath);
return;
}
try {
fs.unlinkSync(filePath);
console.log(chalk.red('DELETED'), filePath);
} catch (ex) {
console.log(chalk.red('DELETE failed'), filePath);
console.log(ex);
}
} | @fileoverview Finds translated docs that no longer have a matching EN
version.
@author Pete LePage <petele@google.com> | deleteFile | javascript | google/WebFundamentals | tools/findOrphanedL10N.js | https://github.com/google/WebFundamentals/blob/master/tools/findOrphanedL10N.js | Apache-2.0 |
function go(lang) {
opts.srcBase = `src/content/${lang}/`;
console.log(chalk.cyan(opts.srcBase));
const files = glob.find(patterns, opts);
files.forEach((file) => {
try {
const enVersion = 'src/content/en/' + file;
fs.accessSync(enVersion, fs.R_OK);
} catch (ex) {
deleteFile(opts.srcBa... | @fileoverview Finds translated docs that no longer have a matching EN
version.
@author Pete LePage <petele@google.com> | go | javascript | google/WebFundamentals | tools/findOrphanedL10N.js | https://github.com/google/WebFundamentals/blob/master/tools/findOrphanedL10N.js | Apache-2.0 |
function getFileList(base) {
let opts = {
srcBase: base,
prefixBase: true,
filter: 'isFile'
};
return glob.find('**/*', opts);
} | @fileoverview Imports a collection of translated files
@author Pete LePage <petele@google.com> | getFileList | javascript | google/WebFundamentals | tools/importTranslations.js | https://github.com/google/WebFundamentals/blob/master/tools/importTranslations.js | Apache-2.0 |
function readFile(filename) {
try {
let contents = fs.readFileSync(filename, 'utf8');
return contents;
} catch (ex) {
return null;
}
} | @fileoverview Imports a collection of translated files
@author Pete LePage <petele@google.com> | readFile | javascript | google/WebFundamentals | tools/importTranslations.js | https://github.com/google/WebFundamentals/blob/master/tools/importTranslations.js | Apache-2.0 |
function isFunction(functionToCheck) {
var getType = {};
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
} | Check if the given variable is a function
@method
@memberof Popper.Utils
@argument {Any} functionToCheck - variable to check
@returns {Boolean} answer to: is a function? | isFunction | javascript | MahdiMajidzadeh/bootstrap-v4-rtl | dist/js/bootstrap.bundle.js | https://github.com/MahdiMajidzadeh/bootstrap-v4-rtl/blob/master/dist/js/bootstrap.bundle.js | MIT |
function getStyleComputedProperty(element, property) {
if (element.nodeType !== 1) {
return [];
}
// NOTE: 1 DOM access here
var window = element.ownerDocument.defaultView;
var css = window.getComputedStyle(element, null);
return property ? css[property] : css;
} | Get CSS computed property of the given element
@method
@memberof Popper.Utils
@argument {Eement} element
@argument {String} property | getStyleComputedProperty | javascript | MahdiMajidzadeh/bootstrap-v4-rtl | dist/js/bootstrap.bundle.js | https://github.com/MahdiMajidzadeh/bootstrap-v4-rtl/blob/master/dist/js/bootstrap.bundle.js | MIT |
function getParentNode(element) {
if (element.nodeName === 'HTML') {
return element;
}
return element.parentNode || element.host;
} | Returns the parentNode or the host of the element
@method
@memberof Popper.Utils
@argument {Element} element
@returns {Element} parent | getParentNode | javascript | MahdiMajidzadeh/bootstrap-v4-rtl | dist/js/bootstrap.bundle.js | https://github.com/MahdiMajidzadeh/bootstrap-v4-rtl/blob/master/dist/js/bootstrap.bundle.js | MIT |
function getScrollParent(element) {
// Return body, `getScroll` will take care to get the correct `scrollTop` from it
if (!element) {
return document.body;
}
switch (element.nodeName) {
case 'HTML':
case 'BODY':
return element.ownerDocument.body;
case '#document':
... | Returns the scrolling parent of the given element
@method
@memberof Popper.Utils
@argument {Element} element
@returns {Element} scroll parent | getScrollParent | javascript | MahdiMajidzadeh/bootstrap-v4-rtl | dist/js/bootstrap.bundle.js | https://github.com/MahdiMajidzadeh/bootstrap-v4-rtl/blob/master/dist/js/bootstrap.bundle.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.