@graphql-inspector/similar-command 0.0.0-canary.da4bdcc → 0.0.0-canary.e88122e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,5 +1,13 @@
1
- import { GlobalArgs } from '@graphql-inspector/commands';
2
- declare const _default: import("../../commands/src").CommandFactory<{}, {
1
+ import { GlobalArgs, CommandFactory } from '@graphql-inspector/commands';
2
+ import { GraphQLSchema } from 'graphql';
3
+ export { CommandFactory };
4
+ export declare function handler({ schema, writePath, type, threshold, }: {
5
+ schema: GraphQLSchema;
6
+ writePath?: string;
7
+ type?: string;
8
+ threshold?: number;
9
+ }): void;
10
+ declare const _default: CommandFactory<{}, {
3
11
  schema: string;
4
12
  name?: string | undefined;
5
13
  threshold?: number | undefined;
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  const tslib = require('tslib');
4
6
  const commands = require('@graphql-inspector/commands');
5
7
  const logger = require('@graphql-inspector/logger');
@@ -7,19 +9,63 @@ const core = require('@graphql-inspector/core');
7
9
  const path = require('path');
8
10
  const fs = require('fs');
9
11
 
12
+ function handler({ schema, writePath, type, threshold, }) {
13
+ const shouldWrite = typeof writePath !== 'undefined';
14
+ const similarMap = core.similar(schema, type, threshold);
15
+ if (!Object.keys(similarMap).length) {
16
+ logger.Logger.info('No similar types found');
17
+ }
18
+ else {
19
+ for (const typeName in similarMap) {
20
+ if (similarMap.hasOwnProperty(typeName)) {
21
+ const matches = similarMap[typeName];
22
+ const prefix = core.getTypePrefix(schema.getType(typeName));
23
+ const sourceType = logger.chalk.bold(typeName);
24
+ const name = matches.bestMatch.target.typeId;
25
+ logger.Logger.log('');
26
+ logger.Logger.log(`${prefix} ${sourceType}`);
27
+ logger.Logger.log(printResult(name, matches.bestMatch.rating));
28
+ matches.ratings.forEach((match) => {
29
+ logger.Logger.log(printResult(match.target.typeId, match.rating));
30
+ });
31
+ }
32
+ }
33
+ if (shouldWrite) {
34
+ if (typeof writePath !== 'string') {
35
+ throw new Error(`--write is not valid file path: ${writePath}`);
36
+ }
37
+ const absPath = commands.ensureAbsolute(writePath);
38
+ const ext = path.extname(absPath).replace('.', '').toLocaleLowerCase();
39
+ let output = undefined;
40
+ const results = transformMap(similarMap);
41
+ if (ext === 'json') {
42
+ output = outputJSON(results);
43
+ }
44
+ if (output) {
45
+ fs.writeFileSync(absPath, output, {
46
+ encoding: 'utf-8',
47
+ });
48
+ logger.Logger.success(`Available at ${absPath}\n`);
49
+ }
50
+ else {
51
+ throw new Error(`Extension ${ext} is not supported`);
52
+ }
53
+ }
54
+ }
55
+ }
10
56
  const index = commands.createCommand((api) => {
11
- const { loaders, interceptArguments, interceptPositional, interceptOptions, } = api;
57
+ const { loaders } = api;
12
58
  return {
13
59
  command: 'similar <schema>',
14
60
  describe: 'Find similar types in a schema',
15
61
  builder(yargs) {
16
62
  return yargs
17
- .positional('schema', interceptPositional('schema', {
63
+ .positional('schema', {
18
64
  describe: 'Point to a schema',
19
65
  type: 'string',
20
66
  demandOption: true,
21
- }))
22
- .options(interceptOptions({
67
+ })
68
+ .options({
23
69
  n: {
24
70
  alias: 'name',
25
71
  describe: 'Name of a type',
@@ -35,59 +81,24 @@ const index = commands.createCommand((api) => {
35
81
  describe: 'Write a file with stats',
36
82
  type: 'string',
37
83
  },
38
- }));
84
+ });
39
85
  },
40
86
  handler(args) {
87
+ var _a;
41
88
  return tslib.__awaiter(this, void 0, void 0, function* () {
42
- interceptArguments(args);
43
89
  const { headers, token } = commands.parseGlobalArgs(args);
44
90
  const writePath = args.write;
45
- const shouldWrite = typeof writePath !== 'undefined';
91
+ const type = args.name;
92
+ const threshold = args.threshold;
93
+ const apolloFederation = args.federation || false;
94
+ const aws = args.aws || false;
95
+ const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
46
96
  const schema = yield loaders.loadSchema(args.schema, {
47
97
  headers,
48
98
  token,
49
- });
50
- const similarMap = core.similar(schema, args.name, args.threshold);
51
- if (!Object.keys(similarMap).length) {
52
- logger.Logger.info('No similar types found');
53
- }
54
- else {
55
- for (const typeName in similarMap) {
56
- if (similarMap.hasOwnProperty(typeName)) {
57
- const matches = similarMap[typeName];
58
- const prefix = core.getTypePrefix(schema.getType(typeName));
59
- const sourceType = logger.chalk.bold(typeName);
60
- const name = matches.bestMatch.target.typeId;
61
- logger.Logger.log('');
62
- logger.Logger.log(`${prefix} ${sourceType}`);
63
- logger.Logger.log(printResult(name, matches.bestMatch.rating));
64
- matches.ratings.forEach((match) => {
65
- logger.Logger.log(printResult(match.target.typeId, match.rating));
66
- });
67
- }
68
- }
69
- if (shouldWrite) {
70
- if (typeof writePath !== 'string') {
71
- throw new Error(`--write is not valid file path: ${writePath}`);
72
- }
73
- const absPath = commands.ensureAbsolute(writePath);
74
- const ext = path.extname(absPath).replace('.', '').toLocaleLowerCase();
75
- let output = undefined;
76
- const results = transformMap(similarMap);
77
- if (ext === 'json') {
78
- output = outputJSON(results);
79
- }
80
- if (output) {
81
- fs.writeFileSync(absPath, output, {
82
- encoding: 'utf-8',
83
- });
84
- logger.Logger.success(`Available at ${absPath}\n`);
85
- }
86
- else {
87
- throw new Error(`Extension ${ext} is not supported`);
88
- }
89
- }
90
- }
99
+ method,
100
+ }, apolloFederation, aws);
101
+ return handler({ schema, writePath, type, threshold });
91
102
  });
92
103
  },
93
104
  };
@@ -136,5 +147,5 @@ function formatRating(ratio) {
136
147
  return Math.floor(ratio * 100);
137
148
  }
138
149
 
139
- module.exports = index;
140
- //# sourceMappingURL=index.cjs.js.map
150
+ exports.default = index;
151
+ exports.handler = handler;
@@ -5,19 +5,63 @@ import { similar, getTypePrefix } from '@graphql-inspector/core';
5
5
  import { extname } from 'path';
6
6
  import { writeFileSync } from 'fs';
7
7
 
8
+ function handler({ schema, writePath, type, threshold, }) {
9
+ const shouldWrite = typeof writePath !== 'undefined';
10
+ const similarMap = similar(schema, type, threshold);
11
+ if (!Object.keys(similarMap).length) {
12
+ Logger.info('No similar types found');
13
+ }
14
+ else {
15
+ for (const typeName in similarMap) {
16
+ if (similarMap.hasOwnProperty(typeName)) {
17
+ const matches = similarMap[typeName];
18
+ const prefix = getTypePrefix(schema.getType(typeName));
19
+ const sourceType = chalk.bold(typeName);
20
+ const name = matches.bestMatch.target.typeId;
21
+ Logger.log('');
22
+ Logger.log(`${prefix} ${sourceType}`);
23
+ Logger.log(printResult(name, matches.bestMatch.rating));
24
+ matches.ratings.forEach((match) => {
25
+ Logger.log(printResult(match.target.typeId, match.rating));
26
+ });
27
+ }
28
+ }
29
+ if (shouldWrite) {
30
+ if (typeof writePath !== 'string') {
31
+ throw new Error(`--write is not valid file path: ${writePath}`);
32
+ }
33
+ const absPath = ensureAbsolute(writePath);
34
+ const ext = extname(absPath).replace('.', '').toLocaleLowerCase();
35
+ let output = undefined;
36
+ const results = transformMap(similarMap);
37
+ if (ext === 'json') {
38
+ output = outputJSON(results);
39
+ }
40
+ if (output) {
41
+ writeFileSync(absPath, output, {
42
+ encoding: 'utf-8',
43
+ });
44
+ Logger.success(`Available at ${absPath}\n`);
45
+ }
46
+ else {
47
+ throw new Error(`Extension ${ext} is not supported`);
48
+ }
49
+ }
50
+ }
51
+ }
8
52
  const index = createCommand((api) => {
9
- const { loaders, interceptArguments, interceptPositional, interceptOptions, } = api;
53
+ const { loaders } = api;
10
54
  return {
11
55
  command: 'similar <schema>',
12
56
  describe: 'Find similar types in a schema',
13
57
  builder(yargs) {
14
58
  return yargs
15
- .positional('schema', interceptPositional('schema', {
59
+ .positional('schema', {
16
60
  describe: 'Point to a schema',
17
61
  type: 'string',
18
62
  demandOption: true,
19
- }))
20
- .options(interceptOptions({
63
+ })
64
+ .options({
21
65
  n: {
22
66
  alias: 'name',
23
67
  describe: 'Name of a type',
@@ -33,59 +77,24 @@ const index = createCommand((api) => {
33
77
  describe: 'Write a file with stats',
34
78
  type: 'string',
35
79
  },
36
- }));
80
+ });
37
81
  },
38
82
  handler(args) {
83
+ var _a;
39
84
  return __awaiter(this, void 0, void 0, function* () {
40
- interceptArguments(args);
41
85
  const { headers, token } = parseGlobalArgs(args);
42
86
  const writePath = args.write;
43
- const shouldWrite = typeof writePath !== 'undefined';
87
+ const type = args.name;
88
+ const threshold = args.threshold;
89
+ const apolloFederation = args.federation || false;
90
+ const aws = args.aws || false;
91
+ const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST';
44
92
  const schema = yield loaders.loadSchema(args.schema, {
45
93
  headers,
46
94
  token,
47
- });
48
- const similarMap = similar(schema, args.name, args.threshold);
49
- if (!Object.keys(similarMap).length) {
50
- Logger.info('No similar types found');
51
- }
52
- else {
53
- for (const typeName in similarMap) {
54
- if (similarMap.hasOwnProperty(typeName)) {
55
- const matches = similarMap[typeName];
56
- const prefix = getTypePrefix(schema.getType(typeName));
57
- const sourceType = chalk.bold(typeName);
58
- const name = matches.bestMatch.target.typeId;
59
- Logger.log('');
60
- Logger.log(`${prefix} ${sourceType}`);
61
- Logger.log(printResult(name, matches.bestMatch.rating));
62
- matches.ratings.forEach((match) => {
63
- Logger.log(printResult(match.target.typeId, match.rating));
64
- });
65
- }
66
- }
67
- if (shouldWrite) {
68
- if (typeof writePath !== 'string') {
69
- throw new Error(`--write is not valid file path: ${writePath}`);
70
- }
71
- const absPath = ensureAbsolute(writePath);
72
- const ext = extname(absPath).replace('.', '').toLocaleLowerCase();
73
- let output = undefined;
74
- const results = transformMap(similarMap);
75
- if (ext === 'json') {
76
- output = outputJSON(results);
77
- }
78
- if (output) {
79
- writeFileSync(absPath, output, {
80
- encoding: 'utf-8',
81
- });
82
- Logger.success(`Available at ${absPath}\n`);
83
- }
84
- else {
85
- throw new Error(`Extension ${ext} is not supported`);
86
- }
87
- }
88
- }
95
+ method,
96
+ }, apolloFederation, aws);
97
+ return handler({ schema, writePath, type, threshold });
89
98
  });
90
99
  },
91
100
  };
@@ -135,4 +144,4 @@ function formatRating(ratio) {
135
144
  }
136
145
 
137
146
  export default index;
138
- //# sourceMappingURL=index.esm.js.map
147
+ export { handler };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-inspector/similar-command",
3
- "version": "0.0.0-canary.da4bdcc",
3
+ "version": "0.0.0-canary.e88122e",
4
4
  "description": "Find similar types in GraphQL Schema",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
- "graphql": "^0.13.0 || ^14.0.0 || ^15.0.0"
7
+ "graphql": "^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-inspector/commands": "0.0.0-canary.da4bdcc",
11
- "@graphql-inspector/core": "0.0.0-canary.da4bdcc",
12
- "@graphql-inspector/logger": "0.0.0-canary.da4bdcc",
10
+ "@graphql-inspector/commands": "0.0.0-canary.e88122e",
11
+ "@graphql-inspector/core": "0.0.0-canary.e88122e",
12
+ "@graphql-inspector/logger": "0.0.0-canary.e88122e",
13
13
  "tslib": "^2.0.0"
14
14
  },
15
15
  "repository": {
@@ -29,10 +29,20 @@
29
29
  "url": "https://github.com/kamilkisiela"
30
30
  },
31
31
  "license": "MIT",
32
- "main": "index.cjs.js",
33
- "module": "index.esm.js",
32
+ "main": "index.js",
33
+ "module": "index.mjs",
34
34
  "typings": "index.d.ts",
35
35
  "typescript": {
36
36
  "definition": "index.d.ts"
37
+ },
38
+ "exports": {
39
+ ".": {
40
+ "require": "./index.js",
41
+ "import": "./index.mjs"
42
+ },
43
+ "./*": {
44
+ "require": "./*.js",
45
+ "import": "./*.mjs"
46
+ }
37
47
  }
38
48
  }
package/index.cjs.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../../dist/commands/similar/src/index.js"],"sourcesContent":["import { __awaiter } from \"tslib\";\nimport { createCommand, ensureAbsolute, parseGlobalArgs, } from '@graphql-inspector/commands';\nimport { Logger, figures, chalk } from '@graphql-inspector/logger';\nimport { similar as findSimilar, getTypePrefix, } from '@graphql-inspector/core';\nimport { extname } from 'path';\nimport { writeFileSync } from 'fs';\nexport default createCommand((api) => {\n const { loaders, interceptArguments, interceptPositional, interceptOptions, } = api;\n return {\n command: 'similar <schema>',\n describe: 'Find similar types in a schema',\n builder(yargs) {\n return yargs\n .positional('schema', interceptPositional('schema', {\n describe: 'Point to a schema',\n type: 'string',\n demandOption: true,\n }))\n .options(interceptOptions({\n n: {\n alias: 'name',\n describe: 'Name of a type',\n type: 'string',\n },\n t: {\n alias: 'threshold',\n describe: 'Threshold of similarity ratio',\n type: 'number',\n },\n w: {\n alias: 'write',\n describe: 'Write a file with stats',\n type: 'string',\n },\n }));\n },\n handler(args) {\n return __awaiter(this, void 0, void 0, function* () {\n interceptArguments(args);\n const { headers, token } = parseGlobalArgs(args);\n const writePath = args.write;\n const shouldWrite = typeof writePath !== 'undefined';\n const schema = yield loaders.loadSchema(args.schema, {\n headers,\n token,\n });\n const similarMap = findSimilar(schema, args.name, args.threshold);\n if (!Object.keys(similarMap).length) {\n Logger.info('No similar types found');\n }\n else {\n for (const typeName in similarMap) {\n if (similarMap.hasOwnProperty(typeName)) {\n const matches = similarMap[typeName];\n const prefix = getTypePrefix(schema.getType(typeName));\n const sourceType = chalk.bold(typeName);\n const name = matches.bestMatch.target.typeId;\n Logger.log('');\n Logger.log(`${prefix} ${sourceType}`);\n Logger.log(printResult(name, matches.bestMatch.rating));\n matches.ratings.forEach((match) => {\n Logger.log(printResult(match.target.typeId, match.rating));\n });\n }\n }\n if (shouldWrite) {\n if (typeof writePath !== 'string') {\n throw new Error(`--write is not valid file path: ${writePath}`);\n }\n const absPath = ensureAbsolute(writePath);\n const ext = extname(absPath).replace('.', '').toLocaleLowerCase();\n let output = undefined;\n const results = transformMap(similarMap);\n if (ext === 'json') {\n output = outputJSON(results);\n }\n if (output) {\n writeFileSync(absPath, output, {\n encoding: 'utf-8',\n });\n Logger.success(`Available at ${absPath}\\n`);\n }\n else {\n throw new Error(`Extension ${ext} is not supported`);\n }\n }\n }\n });\n },\n };\n});\nfunction indent(line, space) {\n return line.padStart(line.length + space, ' ');\n}\nfunction transformMap(similarMap) {\n const results = {};\n for (const typename in similarMap) {\n if (similarMap.hasOwnProperty(typename)) {\n const result = similarMap[typename];\n results[typename] = [];\n if (result.bestMatch) {\n results[typename].push(trasformResult(result.bestMatch));\n }\n if (result.ratings) {\n results[typename].push(...result.ratings.map(trasformResult));\n }\n }\n }\n return results;\n}\nfunction trasformResult(record) {\n return {\n typename: record.target.typeId,\n rating: record.rating,\n };\n}\nfunction outputJSON(results) {\n return JSON.stringify(results);\n}\nfunction printResult(name, rating) {\n const percentage = chalk.grey(`(${formatRating(rating)}%)`);\n return indent(`${printScale(rating)} ${percentage} ${name}`, 0);\n}\nfunction printScale(ratio) {\n const percentage = Math.floor(ratio * 100);\n const levels = [0, 30, 50, 70, 90];\n return levels\n .map((level) => percentage >= level)\n .map((enabled) => (enabled ? figures.bullet : chalk.gray(figures.bullet)))\n .join('');\n}\nfunction formatRating(ratio) {\n return Math.floor(ratio * 100);\n}\n//# sourceMappingURL=index.js.map"],"names":["createCommand","__awaiter","parseGlobalArgs","findSimilar","Logger","getTypePrefix","chalk","ensureAbsolute","extname","writeFileSync","figures"],"mappings":";;;;;;;;;AAMA,cAAeA,sBAAa,CAAC,CAAC,GAAG,KAAK;AACtC,IAAI,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,gBAAgB,GAAG,GAAG,GAAG,CAAC;AACxF,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,kBAAkB;AACnC,QAAQ,QAAQ,EAAE,gCAAgC;AAClD,QAAQ,OAAO,CAAC,KAAK,EAAE;AACvB,YAAY,OAAO,KAAK;AACxB,iBAAiB,UAAU,CAAC,QAAQ,EAAE,mBAAmB,CAAC,QAAQ,EAAE;AACpE,gBAAgB,QAAQ,EAAE,mBAAmB;AAC7C,gBAAgB,IAAI,EAAE,QAAQ;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AAC;AACD,SAAS,UAAU,CAAC,KAAK,EAAE;AAC3B,IAAI,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;AAC/C,IAAI,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACvC,IAAI,OAAO,MAAM;AACjB,SAAS,GAAG,CAAC,CAAC,KAAK,KAAK,UAAU,IAAI,KAAK,CAAC;AAC5C,SAAS,GAAG,CAAC,CAAC,OAAO,MAAM,OAAO,GAAGI,cAAO,CAAC,MAAM,GAAGJ,YAAK,CAAC,IAAI,CAACI,cAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AAClF,SAAS,IAAI,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AACD,SAAS,YAAY,CAAC,KAAK,EAAE;AAC7B,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;AACnC;;;;"}
package/index.esm.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../../dist/commands/similar/src/index.js"],"sourcesContent":["import { __awaiter } from \"tslib\";\nimport { createCommand, ensureAbsolute, parseGlobalArgs, } from '@graphql-inspector/commands';\nimport { Logger, figures, chalk } from '@graphql-inspector/logger';\nimport { similar as findSimilar, getTypePrefix, } from '@graphql-inspector/core';\nimport { extname } from 'path';\nimport { writeFileSync } from 'fs';\nexport default createCommand((api) => {\n const { loaders, interceptArguments, interceptPositional, interceptOptions, } = api;\n return {\n command: 'similar <schema>',\n describe: 'Find similar types in a schema',\n builder(yargs) {\n return yargs\n .positional('schema', interceptPositional('schema', {\n describe: 'Point to a schema',\n type: 'string',\n demandOption: true,\n }))\n .options(interceptOptions({\n n: {\n alias: 'name',\n describe: 'Name of a type',\n type: 'string',\n },\n t: {\n alias: 'threshold',\n describe: 'Threshold of similarity ratio',\n type: 'number',\n },\n w: {\n alias: 'write',\n describe: 'Write a file with stats',\n type: 'string',\n },\n }));\n },\n handler(args) {\n return __awaiter(this, void 0, void 0, function* () {\n interceptArguments(args);\n const { headers, token } = parseGlobalArgs(args);\n const writePath = args.write;\n const shouldWrite = typeof writePath !== 'undefined';\n const schema = yield loaders.loadSchema(args.schema, {\n headers,\n token,\n });\n const similarMap = findSimilar(schema, args.name, args.threshold);\n if (!Object.keys(similarMap).length) {\n Logger.info('No similar types found');\n }\n else {\n for (const typeName in similarMap) {\n if (similarMap.hasOwnProperty(typeName)) {\n const matches = similarMap[typeName];\n const prefix = getTypePrefix(schema.getType(typeName));\n const sourceType = chalk.bold(typeName);\n const name = matches.bestMatch.target.typeId;\n Logger.log('');\n Logger.log(`${prefix} ${sourceType}`);\n Logger.log(printResult(name, matches.bestMatch.rating));\n matches.ratings.forEach((match) => {\n Logger.log(printResult(match.target.typeId, match.rating));\n });\n }\n }\n if (shouldWrite) {\n if (typeof writePath !== 'string') {\n throw new Error(`--write is not valid file path: ${writePath}`);\n }\n const absPath = ensureAbsolute(writePath);\n const ext = extname(absPath).replace('.', '').toLocaleLowerCase();\n let output = undefined;\n const results = transformMap(similarMap);\n if (ext === 'json') {\n output = outputJSON(results);\n }\n if (output) {\n writeFileSync(absPath, output, {\n encoding: 'utf-8',\n });\n Logger.success(`Available at ${absPath}\\n`);\n }\n else {\n throw new Error(`Extension ${ext} is not supported`);\n }\n }\n }\n });\n },\n };\n});\nfunction indent(line, space) {\n return line.padStart(line.length + space, ' ');\n}\nfunction transformMap(similarMap) {\n const results = {};\n for (const typename in similarMap) {\n if (similarMap.hasOwnProperty(typename)) {\n const result = similarMap[typename];\n results[typename] = [];\n if (result.bestMatch) {\n results[typename].push(trasformResult(result.bestMatch));\n }\n if (result.ratings) {\n results[typename].push(...result.ratings.map(trasformResult));\n }\n }\n }\n return results;\n}\nfunction trasformResult(record) {\n return {\n typename: record.target.typeId,\n rating: record.rating,\n };\n}\nfunction outputJSON(results) {\n return JSON.stringify(results);\n}\nfunction printResult(name, rating) {\n const percentage = chalk.grey(`(${formatRating(rating)}%)`);\n return indent(`${printScale(rating)} ${percentage} ${name}`, 0);\n}\nfunction printScale(ratio) {\n const percentage = Math.floor(ratio * 100);\n const levels = [0, 30, 50, 70, 90];\n return levels\n .map((level) => percentage >= level)\n .map((enabled) => (enabled ? figures.bullet : chalk.gray(figures.bullet)))\n .join('');\n}\nfunction formatRating(ratio) {\n return Math.floor(ratio * 100);\n}\n//# sourceMappingURL=index.js.map"],"names":["findSimilar"],"mappings":";;;;;;;AAMA,cAAe,aAAa,CAAC,CAAC,GAAG,KAAK;AACtC,IAAI,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,gBAAgB,GAAG,GAAG,GAAG,CAAC;AACxF,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,kBAAkB;AACnC,QAAQ,QAAQ,EAAE,gCAAgC;AAClD,QAAQ,OAAO,CAAC,KAAK,EAAE;AACvB,YAAY,OAAO,KAAK;AACxB,iBAAiB,UAAU,CAAC,QAAQ,EAAE,mBAAmB,CAAC,QAAQ,EAAE;AACpE,gBAAgB,QAAQ,EAAE,mBAAmB;AAC7C,gBAAgB,IAAI,EAAE,QAAQ;AAC9B,gBAAgB,YAAY,EAAE,IAAI;AAClC,aAAa,CAAC,CAAC;AACf,iBAAiB,OAAO,CAAC,gBAAgB,CAAC;AAC1C,gBAAgB,CAAC,EAAE;AACnB,oBAAoB,KAAK,EAAE,MAAM;AACjC,oBAAoB,QAAQ,EAAE,gBAAgB;AAC9C,oBAAoB,IAAI,EAAE,QAAQ;AAClC,iBAAiB;AACjB,gBAAgB,CAAC,EAAE;AACnB,oBAAoB,KAAK,EAAE,WAAW;AACtC,oBAAoB,QAAQ,EAAE,+BAA+B;AAC7D,oBAAoB,IAAI,EAAE,QAAQ;AAClC,iBAAiB;AACjB,gBAAgB,CAAC,EAAE;AACnB,oBAAoB,KAAK,EAAE,OAAO;AAClC,oBAAoB,QAAQ,EA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