Skip to content

Commit

Permalink
chore: remove for-in (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuong Tran authored Aug 7, 2020
1 parent 3443b0f commit 0d5d50b
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 9 deletions.
42 changes: 42 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/hera.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@103cuong/hera-js",
"version": "0.2.0",
"version": "0.2.1",
"description": "👩🏼‍💻 Simple and lightweight GraphQL client.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import axios, { AxiosResponse, AxiosRequestConfig } from 'axios';

function formatVariables(variables: any): any {
let formatedVariables = JSON.stringify(variables);
formatedVariables = formatedVariables.replace(/"([^"]+)"\s*:\s*/g, '$1:');
return formatedVariables;
let formattedVariables = JSON.stringify(variables);
formattedVariables = formattedVariables.replace(/"([^"]+)"\s*:\s*/g, '$1:');
return formattedVariables;
}
function formatQuery(query: string, variables: any): string {
let formatedQuery = query;
for (const key in variables) {
let formattedQuery = query;
Object.keys(variables).forEach((key) => {
const regex = new RegExp(`\\$${key}`, 'g');
formatedQuery = formatedQuery.replace(regex, formatVariables(variables[key]));
}
return formatedQuery;
formattedQuery = formattedQuery.replace(regex, formatVariables(variables[key]));
});
return formattedQuery;
}

interface Option {
Expand Down

0 comments on commit 0d5d50b

Please sign in to comment.