How to use didyoumean2 - 8 common examples

To help you get started, we’ve selected a few didyoumean2 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 hack-chat / main / server / src / serverLib / CommandManager.js View on Github external
handleFail(server, socket, data) {
    const maybe = didYouMean(data.cmd, this.all().map((c) => c.info.name), {
      threshold: 5,
      thresholdType: 'edit-distance',
    });

    if (maybe) {
      // Found a suggestion, pass it on to their dyslexic self
      return this.handleCommand(server, socket, {
        cmd: 'socketreply',
        cmdKey: server.cmdKey,
        text: `Command not found, did you mean: \`${maybe}\`?`,
      });
    }

    // Request so mangled that I don't even. . .
    return this.handleCommand(server, socket, {
      cmd: 'socketreply',
github runem / lit-analyzer / packages / lit-analyzer / src / analyze / util / find-best-match.ts View on Github external
export function findBestStringMatch(
	find: string,
	elements: string[],
	options: Omit, "matchKey"> = {
		caseSensitive: true,
		threshold: 0.5
	}
): string | undefined {
	const matches = didYouMean(find, elements, options);
	return typeof matches === "string" ? matches : Array.isArray(matches) ? matches[0] : undefined;
}
github contentful / contentful-migration / src / lib / intent-validator / field-movement.ts View on Github external
}

      if (sourceFieldId === pivot) {
        return [
          {
            type: 'InvalidMovement',
            message: validationErrors.INVALID_MOVEMENT_WITH_SELF(sourceFieldId),
            details: { intent }
          }
        ]
      }

      return []
    }

    const suggestion = didYouMean(movement, validMoves)

    let message = validationErrors.INVALID_MOVEMENT_NAME(movement)

    if (suggestion) {
      message = validationErrors.INVALID_MOVEMENT_NAME_WITH_SUGGESTION(movement, suggestion)
    }

    return [
      {
        type: 'InvalidMovement',
        message,
        details: { intent }
      }
    ]
  }
}
github runem / lit-analyzer / packages / lit-analyzer / src / analyze / util / find-best-match.ts View on Github external
export function findBestMatch(find: string, elements: T[], options: FindBestMatchOptions): T | undefined {
	options.caseSensitive = "caseSensitive" in options ? options.caseSensitive : false;
	options.threshold = "threshold" in options ? options.threshold : 0.5;

	return (didYouMean(find, elements, {
		caseSensitive: options.caseSensitive,
		threshold: options.threshold,
		matchPath: [options.matchKey] as [string],
		returnType: dym.ReturnTypeEnums.FIRST_CLOSEST_MATCH,
		trimSpaces: false
	}) as unknown) as T | undefined;
}
github seek-oss / braid-design-system / site / src / App / foundations / iconography / iconography.tsx View on Github external
onChange={({ currentTarget }) => {
                const searchText = currentTarget.value;

                setSearchTerm(searchText);
                const filteredList = iconNames.filter(
                  ({ name }) =>
                    searchText.length === 0 ||
                    name.toLowerCase().indexOf(searchText.toLowerCase()) > -1,
                );

                if (filteredList.length === 0) {
                  const suggestions =
                    didYouMean(searchText, iconNames, {
                      returnType: ReturnTypeEnums.ALL_CLOSEST_MATCHES,
                      matchPath: ['displayName'],
                    }) ?? [];
                  const suggestionList = Array.isArray(suggestions)
                    ? suggestions
                    : [suggestions];

                  setDisambiguated(suggestionList && suggestionList.length > 0);
                  setIconList(suggestionList);
                } else {
                  setDisambiguated(false);
                  setIconList(filteredList);
                }
              }}
            />
github runem / lit-analyzer / packages / lit-analyzer / src / analyze / util / find-best-match.ts View on Github external
export function findBestMatch(find: string, elements: T[], options: FindBestMatchOptions): T | undefined {
	options.caseSensitive = "caseSensitive" in options ? options.caseSensitive : false;
	options.threshold = "threshold" in options ? options.threshold : 0.5;

	return (didYouMean(find, elements, {
		caseSensitive: options.caseSensitive,
		threshold: options.threshold,
		matchPath: [options.matchKey] as [string],
		returnType: dym.ReturnTypeEnums.FIRST_CLOSEST_MATCH,
		trimSpaces: false
	}) as unknown) as T | undefined;
}
github seek-oss / braid-design-system / site / src / App / foundations / iconography / iconography.tsx View on Github external
onChange={({ currentTarget }) => {
                const searchText = currentTarget.value;

                setSearchTerm(searchText);
                const filteredList = iconNames.filter(
                  ({ name }) =>
                    searchText.length === 0 ||
                    name.toLowerCase().indexOf(searchText.toLowerCase()) > -1,
                );

                if (filteredList.length === 0) {
                  const suggestions =
                    didYouMean(searchText, iconNames, {
                      returnType: ReturnTypeEnums.ALL_CLOSEST_MATCHES,
                      matchPath: ['displayName'],
                    }) ?? [];
                  const suggestionList = Array.isArray(suggestions)
                    ? suggestions
                    : [suggestions];

                  setDisambiguated(suggestionList && suggestionList.length > 0);
                  setIconList(suggestionList);
                } else {
                  setDisambiguated(false);
                  setIconList(filteredList);
                }
              }}
            />
github seek-oss / sku / context / validateConfig.js View on Github external
.forEach(key => {
      const unknownMessage = `Unknown key '${bold(key)}'.`;
      const suggestedKey = didYouMean(key, availableConfigKeys);
      const suggestedMessage = suggestedKey
        ? ` Did you mean '${bold(suggestedKey)}'?`
        : '';
      errors.push(`:question: ${unknownMessage}${suggestedMessage}`);
    });

didyoumean2

a library for matching human-quality input to a list of potential matches using the Levenshtein distance algorithm

MIT
Latest version published 2 months ago

Package Health Score

80 / 100
Full package analysis