How to use the @sindresorhus/is.string function in @sindresorhus/is

To help you get started, we’ve selected a few @sindresorhus/is examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sx1989827 / DOClever / node_modules / got / index.js View on Github external
throw new TypeError('The `body` option must be a plain Object or Array when the `form` or `json` option is used');
		}

		if (isFormData(body)) {
			// Special case for https://github.com/form-data/form-data
			headers['content-type'] = headers['content-type'] || `multipart/form-data; boundary=${body.getBoundary()}`;
		} else if (opts.form && canBodyBeStringified) {
			headers['content-type'] = headers['content-type'] || 'application/x-www-form-urlencoded';
			opts.body = querystring.stringify(body);
		} else if (opts.json && canBodyBeStringified) {
			headers['content-type'] = headers['content-type'] || 'application/json';
			opts.body = JSON.stringify(body);
		}

		if (is.undefined(headers['content-length']) && is.undefined(headers['transfer-encoding']) && !is.nodeStream(body)) {
			const length = is.string(opts.body) ? Buffer.byteLength(opts.body) : opts.body.length;
			headers['content-length'] = length;
		}

		// Convert buffer to stream to receive upload progress events
		// see https://github.com/sindresorhus/got/pull/322
		if (is.buffer(body)) {
			opts.body = intoStream(body);
			opts.body._buffer = body;
		}

		opts.method = (opts.method || 'POST').toUpperCase();
	}

	if (opts.hostname === 'unix') {
		const matches = /(.+?):(.+)/.exec(opts.path);
github deltachat / deltachat-desktop / conversations / ts / components / conversation / Emojify.tsx View on Github external
function getImageTag({
  match,
  sizeClass,
  key,
}: {
  match: any;
  sizeClass: string | undefined;
  key: string | number;
}) {
  const result = getReplacementData(match[0], match[1], match[2]);

  if (is.string(result)) {
    return <span>{match[0]}</span>;
  }

  const img = findImage(result.value, result.variation);
  const title = getTitle(result.value);

  return (
    // tslint:disable-next-line react-a11y-img-has-alt
    <img title="{`:${title}:`}" data-codepoints="{img.full_idx}" is="" alt="" src="{img.path}">
github sindresorhus / got / source / utils / url-to-options.ts View on Github external
export default (url: URL | UrlWithStringQuery): LegacyURLOptions => {
	// Cast to URL
	url = url as URL;

	const options: LegacyURLOptions = {
		protocol: url.protocol,
		hostname: is.string(url.hostname) && url.hostname.startsWith('[') ? url.hostname.slice(1, -1) : url.hostname,
		host: url.host,
		hash: url.hash,
		search: url.search,
		pathname: url.pathname,
		href: url.href,
		path: `${url.pathname || ''}${url.search || ''}`
	};

	if (is.string(url.port) && url.port.length !== 0) {
		options.port = Number(url.port);
	}

	if (url.username || url.password) {
		options.auth = `${url.username || ''}:${url.password || ''}`;
	}
github throneless-tech / libsignal-service-javascript / src / WebAPI.js View on Github external
function initialize({
  url,
  cdnUrl,
  certificateAuthority,
  contentProxyUrl,
  proxyUrl
}) {
  if (!is.string(url)) {
    throw new Error("WebAPI.initialize: Invalid server url");
  }
  if (!is.string(cdnUrl)) {
    throw new Error("WebAPI.initialize: Invalid cdnUrl");
  }
  if (!is.string(certificateAuthority)) {
    throw new Error("WebAPI.initialize: Invalid certificateAuthority");
  }
  if (!is.string(contentProxyUrl)) {
    throw new Error("WebAPI.initialize: Invalid contentProxyUrl");
  }

  // Thanks to function-hoisting, we can put this return statement before all of the
  //   below function definitions.
  return {
    connect
  };

  // Then we connect to the server with user-specific information. This is the only API
github Hackdromeda / BugBrowser / node_modules / got / index.js View on Github external
throw new TypeError('The `body` option must be a plain Object or Array when the `form` or `json` option is used');
		}

		if (isFormData(body)) {
			// Special case for https://github.com/form-data/form-data
			headers['content-type'] = headers['content-type'] || `multipart/form-data; boundary=${body.getBoundary()}`;
		} else if (opts.form && canBodyBeStringified) {
			headers['content-type'] = headers['content-type'] || 'application/x-www-form-urlencoded';
			opts.body = querystring.stringify(body);
		} else if (opts.json && canBodyBeStringified) {
			headers['content-type'] = headers['content-type'] || 'application/json';
			opts.body = JSON.stringify(body);
		}

		if (is.undefined(headers['content-length']) && is.undefined(headers['transfer-encoding']) && !is.nodeStream(body)) {
			const length = is.string(opts.body) ? Buffer.byteLength(opts.body) : opts.body.length;
			headers['content-length'] = length;
		}

		// Convert buffer to stream to receive upload progress events
		// see https://github.com/sindresorhus/got/pull/322
		if (is.buffer(body)) {
			opts.body = intoStream(body);
			opts.body._buffer = body;
		}

		opts.method = (opts.method || 'POST').toUpperCase();
	}

	if (opts.hostname === 'unix') {
		const matches = /(.+?):(.+)/.exec(opts.path);
github dylang / logging / src / formatters / format-color / format-color.ts View on Github external
export const formatColor = (level: Level, args: unknown[]) => {
    const arg0 = args[0];
    if (is.string(arg0) && is.string(args[1]) && arg0.includes('%s')) {
        const [template, ...params] = args;
        return indentAllLines(format(template, ...params));
    }
    const formattedMessages = args.filter((arg: unknown) => arg !== '').map((arg: unknown) => formatAny(arg));
    const contentJoined = joinStringsWithNewlinesOrSpaces(formattedMessages);
    const contentWithoutExcessIndentation = stripIndent`${contentJoined}`.replace(/ /g, nonBreakingWhitespace);
    dynamicProgress.clear();
    return replaceNonBreakingWhitespaceWithSpace(decorateWithLevel(level, contentWithoutExcessIndentation));
};
github googleapis / cloud-debug-nodejs / src / debuggee.ts View on Github external
constructor(properties: DebuggeeProperties) {
    if (!(this instanceof Debuggee)) {
      return new Debuggee(properties);
    }

    properties = properties || {};

    if (!is.string(properties.project)) {
      throw new Error('properties.project must be a string');
    }
    if (!is.string(properties.uniquifier)) {
      throw new Error('properties.uniquifier must be a string');
    }
    if (!is.string(properties.description)) {
      throw new Error('properties.description must be a string');
    }

    this.project = properties.project;
    this.uniquifier = properties.uniquifier;
    this.description = properties.description;
    this.agentVersion = properties.agentVersion;
    if (properties.labels) {
      this.labels = properties.labels;
    }
    if (properties.sourceContexts) {
      this.sourceContexts = properties.sourceContexts;
    }
    if (properties.statusMessage) {
      this.statusMessage = properties.statusMessage;
    }
github Hackdromeda / BugBrowser / node_modules / got / index.js View on Github external
function normalizeArguments(url, opts) {
	if (!is.string(url) && !is.object(url)) {
		throw new TypeError(`Parameter \`url\` must be a string or object, not ${is(url)}`);
	} else if (is.string(url)) {
		url = url.replace(/^unix:/, 'http://$&');

		try {
			decodeURI(url);
		} catch (err) {
			throw new Error('Parameter `url` must contain valid UTF-8 character sequences');
		}

		url = urlParseLax(url);
		if (url.auth) {
			throw new Error('Basic authentication must be done with the `auth` option');
		}
	} else if (isURL.lenient(url)) {
		url = urlToOptions(url);
	}