lodash#trimStart TypeScript Examples

The following examples show how to use lodash#trimStart. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: core.ts    From backstage with Apache License 2.0 6 votes vote down vote up
/**
 * Build a Gerrit Gitiles url that targets a specific path.
 *
 * @param config - A Gerrit provider config.
 * @param project - The name of the git project
 * @param branch - The branch we will target.
 * @param filePath - The absolute file path.
 * @public
 */
export function builldGerritGitilesUrl(
  config: GerritIntegrationConfig,
  project: string,
  branch: string,
  filePath: string,
): string {
  return `${
    config.gitilesBaseUrl
  }/${project}/+/refs/heads/${branch}/${trimStart(filePath, '/')}`;
}
Example #2
Source File: main.ts    From Adachi-BOT with MIT License 5 votes vote down vote up
protected static header( raw: string, h: string ): string {
		if ( raw.substr( 0, 2 ) === "__" ) {
			return trimStart( raw, "_" );
		} else {
			return h + raw;
		}
	}
Example #3
Source File: switch.ts    From Adachi-BOT with MIT License 5 votes vote down vote up
public match( content: string ): SwitchMatchResult | Unmatch {
		for ( let reg of this.regexps ) {
			const res: RegExpExecArray | null = reg.exec( content );
			if ( !res ) {
				continue;
			}
			
			const [ onKey, offKey ]: [ string, string ] = this.keys;
			const temp: string[] = res.splice( 1 );
			
			let switchKey: string = "";
			if ( temp.includes( onKey ) ) {
				switchKey = onKey;
			}
			if ( temp.includes( offKey ) ) {
				switchKey = offKey;
			}
			
			const isOn = () => switchKey === onKey;
			const match = res[0].replace( / +/g, " " )
								.split( " " )
								.filter( el => el !== switchKey )
								.map( el => trimStart( el ) );
			if ( match.length !== 0 ) {
				if ( this.mode === "single" ) {
					if ( match[0].includes( this.header ) ) {
						match[0] = match[0].split( this.header ).join( "" );
					}
				} else if ( this.mode === "divided" ) {
					if ( match[0].includes( onKey ) ) {
						match[0] = match[0].split( onKey ).join( "" );
					}
					if ( match[0].includes( offKey ) ) {
						match[0] = match[0].split( offKey ).join( "" );
					}
				}
				if ( match[0].length === 0 ) {
					match.shift();
				}
			}
			
			return {
				type: "switch",
				switch: switchKey,
				match, isOn
			};
		}
		
		return { type: "unmatch" };
	}
Example #4
Source File: core.ts    From backstage with Apache License 2.0 5 votes vote down vote up
/**
 * Parse a Gitiles URL and return branch, file path and project.
 *
 * @remarks
 *
 * Gerrit only handles code reviews so it does not have a native way to browse
 * or showing the content of gits. Image if Github only had the "pull requests"
 * tab.
 *
 * Any source code browsing is instead handled by optional services outside
 * Gerrit. The url format chosen for the Gerrit url reader is the one used by
 * the Gitiles project. Gerrit will work perfectly with Backstage without
 * having Gitiles installed but there are some places in the Backstage GUI
 * with links to the url used by the url reader. These will not work unless
 * the urls point to an actual Gitiles installation.
 *
 * Gitiles url:
 * https://g.com/optional_path/\{project\}/+/refs/heads/\{branch\}/\{filePath\}
 *
 *
 * @param url - An URL pointing to a file stored in git.
 * @public
 */

export function parseGerritGitilesUrl(
  config: GerritIntegrationConfig,
  url: string,
): { branch: string; filePath: string; project: string } {
  const urlPath = url.replace(config.gitilesBaseUrl!, '');
  const parts = urlPath.split('/').filter(p => !!p);

  const projectEndIndex = parts.indexOf('+');

  if (projectEndIndex <= 0) {
    throw new Error(`Unable to parse project from url: ${url}`);
  }
  const project = trimStart(parts.slice(0, projectEndIndex).join('/'), '/');

  const branchIndex = parts.indexOf('heads');
  if (branchIndex <= 0) {
    throw new Error(`Unable to parse branch from url: ${url}`);
  }
  const branch = parts[branchIndex + 1];
  const filePath = parts.slice(branchIndex + 2).join('/');

  return {
    branch,
    filePath: filePath === '' ? '/' : filePath,
    project,
  };
}