const extName = (urlStr: string) => { let ext = ''; const index = urlStr.lastIndexOf('.'); if (index >= 0) { ext = urlStr.substr(index); } return ext; }
const truncateString = (str: string, length: number) => { if (str.length <= length) { return str; } const subString = str.substr(0, length); return subString.substr(0, subString.lastIndexOf(' ')) + '…'; }
private updateVersionValue(versionId: string) { let numberVersionId = parseFloat(versionId) if (isNaN(numberVersionId)) { const index = versionId.lastIndexOf('-') if (index > 0) { const strVersion = versionId.substring(0, index) const numberVersion = versionId.substring(index + 1) numberVersionId = parseFloat(numberVersion) if (isNaN(numberVersionId)) { return versionId } else { const newVersionId = numberVersionId + 0.1 return strVersion + '-' + newVersionId.toFixed(1) } } else { return versionId + '-0.1' } } else { return (numberVersionId + 0.1).toFixed(1) } }
/** * Parse single where param * @param {string} whereClause - Any possible where clause e.g: id_ne text_ncontains * @param {string} value - the value of the where clause e.g id_ne=value */ const convertWhereClause = (whereClause, value) => { const separatorIndex = whereClause.lastIndexOf('_'); // eq operator if (separatorIndex === -1) { return { field: whereClause, value }; } // split field and operator const field = whereClause.substring(0, separatorIndex); const operator = whereClause.slice(separatorIndex + 1); if (BOOLEAN_OPERATORS.includes(operator) && field === '') { return { field: null, operator, value: [].concat(value).map(convertWhereParams) }; } // the field as underscores if (!VALID_REST_OPERATORS.includes(operator)) { return { field: whereClause, value }; } return { field, operator, value }; }
const name = decodeURIComponent(url.pathname.substring(url.pathname.lastIndexOf('/') + 1)); const CancelToken = axios.CancelToken; const abortController = new AbortController();
/** * @param {string} fileURL * @param {string} newName */ renameFile(fileURL, newName) { const newURL = new URL(fileURL.substr(0, fileURL.lastIndexOf('/') + 1) + newName); try { if (fs.existsSync(newURL)) return false; fs.renameSync(new URL(fileURL), newURL); return true; } catch (e) { return false; } }
/** * Renders the text section of the tweet. * * @param {string} text The text of the tweet. * @param {Array} urls Optional. An array of URLs that are in the text. * @param {object} card Optional. The card data for this tweet. * * @returns {React.Element} The text section. */ renderText( text, urls = [], card = {} ) { // If the text ends with the card URL, remove it. const cardUrl = card.url || ''; const deCardedText = text.endsWith( cardUrl ) ? text.substr( 0, text.lastIndexOf( cardUrl ) ) : text; const __html = urls.reduce( ( html, url ) => html.replace( new RegExp( '\\(' + url + '\\)', 'g' ), `(<a href="${ url }">${ url }</a>)` ), stripHtmlTags( deCardedText ).replace( new RegExp( '\\n', 'g' ), '<br/>' ) ); // We can enable dangerouslySetInnerHTML here, since the text we're using is stripped // of all HTML tags, then only has safe tags added in createTweetMarkup(). /* eslint-disable react/no-danger */ return <div className="twitter-preview__text" dangerouslySetInnerHTML={ { __html } } />; /* eslint-enabled react/no-danger */ }
var index=path.lastIndexOf(pathLib.sep); index=path.lastIndexOf(pathLib.sep,index-1); var dbPath=path.substring(index).replace(/\\/g,"/"); var pipe=stream.pipe(fs.createWriteStream(path));
if (len == 2 && firstStarPosition == 0 && pattern.lastIndexOf("*") == 1) { return true;
this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1 this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length } else {
/** * Check to see if we should transpile certain files in node_modules * * @param {string} filepath the path of the file to check * @returns {boolean} True if we should transpile it, false if not * * We had a thought to try to find the package.json and use the engines property * to determine what we should transpile, but not all libraries set engines properly * (see d3-array@2.0.0). Instead, we transpile libraries we know to have dropped Node 4 support * are likely to remain so going forward. */ function shouldTranspileDependency( filepath ) { // find the last index of node_modules and check from there // we want <working>/node_modules/a-package/node_modules/foo/index.js to only match foo, not a-package const marker = '/node_modules/'; const lastIndex = filepath.lastIndexOf( marker ); if ( lastIndex === -1 ) { // we're not in node_modules return false; } const checkFrom = lastIndex + marker.length; return nodeModulesToTranspile.some( ( modulePart ) => filepath.startsWith( modulePart, checkFrom ) ); }
var dashIndex = filename.lastIndexOf('_'); if (dashIndex <= 0) { return;
/** * Parse the tld from a given domain name, semi-naively. The function * first parses against a list of tlds that have been sold on WP.com * and falls back to a simplistic "everything after the last dot" approach * if the list of explicitly allowed tlds failed. This is ultimately not comprehensive as that * is a poor base assumption (lots of second level tlds, etc). However, * for our purposes, the approach should be "good enough" for a long time. * * @param {string} domainName The domain name parse the tld from * @returns {string} The TLD or an empty string */ export function getTld( domainName ) { const lastIndexOfDot = domainName.lastIndexOf( '.' ); if ( lastIndexOfDot === -1 ) { return ''; } let tld = parseDomainAgainstTldList( domainName, wpcomMultiLevelTlds ); if ( ! tld ) { tld = domainName.substring( lastIndexOfDot + 1 ); } return tld; }
/** * Parse single where param * @param {string} whereClause - Any possible where clause e.g: id_ne text_ncontains * @param {string} value - the value of the where clause e.g id_ne=value */ const convertWhereClause = (whereClause, value) => { const separatorIndex = whereClause.lastIndexOf('_'); // eq operator if (separatorIndex === -1) { return { field: whereClause, value }; } // split field and operator const field = whereClause.substring(0, separatorIndex); const operator = whereClause.slice(separatorIndex + 1); if (BOOLEAN_OPERATORS.includes(operator) && field === '') { return { field: null, operator, value: [].concat(value).map(convertWhereParams) }; } // the field as underscores if (!VALID_REST_OPERATORS.includes(operator)) { return { field: whereClause, value }; } return { field, operator, value }; }
const name = decodeURIComponent(url.pathname.substring(url.pathname.lastIndexOf('/') + 1)); const CancelToken = axios.CancelToken; const abortController = new AbortController();