Browse Source

v1.2.1: allowed use of callbacks if desired

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan 5 years ago
parent
commit
ad998ab9d9
5 changed files with 15 additions and 19 deletions
  1. 5 11
      README.md
  2. 0 0
      dist/lofig.min.js
  3. 4 2
      example/index.html
  4. 5 4
      lofig.js
  5. 1 2
      package.json

+ 5 - 11
README.md

@@ -19,21 +19,15 @@ import 'lofig' from 'lofig'; // not necessary if using CDN Link
 lofig.folder = 'config/default.json';
 
 // check if property exists
-
 await lofig.has('secret');
-// OR
-lofig.has('secret').then(res => {
-	if (res) console.log("secret is defined!");
-})
 
 // return property
-
 await lofig.get('secret');
-// OR
-lofig.get('secret').then(secret => {
-	if (secret) console.log("secret:", secret);
-})
 
+// NOTE: You can also use callbacks e.g.
+lofig.get('secret', res => {
+	console.log('secret', res);
+})
 ```
 
-See [example](https://github.com/jonathan-grah/lofig/tree/master/example) folder for more details.
+See the [example](https://github.com/jonathan-grah/lofig/tree/master/example) folder for more details.

File diff suppressed because it is too large
+ 0 - 0
dist/lofig.min.js


+ 4 - 2
example/index.html

@@ -2,7 +2,9 @@
 <html lang="en">
 <head>
 	<meta charset="UTF-8">
-	<title>Document</title>
+	<meta name="viewport" content="width=device-width, initial-scale=1.0">
+	<meta http-equiv="X-UA-Compatible" content="ie=edge">
+	<title>Lofig | Example</title>
 </head>
 <body>
 	<h3>
@@ -17,4 +19,4 @@
 		})();
 	</script>
 </body>
-</html>
+</html>

+ 5 - 4
lofig.js

@@ -1,7 +1,6 @@
-
 window.lofig = {
 	folder: 'config/default.json',
-	get: query => {
+	get: (query, cb) => {
 		return fetch(lofig.folder)
 			.then(response => {
 				return response.json();
@@ -11,12 +10,13 @@ window.lofig = {
 						json = json[property];
 					});
 
-				return json;
+				if (cb) return cb(json);
+				else return json;
 			}).catch(err => {
 				console.log('parsing failed', err);
 			});
 	},
-	has: query => {
+	has: (query, cb) => {
 		return fetch(lofig.folder)
 			.then(response => {
 				return response.json();
@@ -26,6 +26,7 @@ window.lofig = {
 						json = json[property];
 					});
 
+				if (cb) return cb(json);
 				return json;
 			}).catch(err => {
 				console.log('parsing failed', err);

+ 1 - 2
package.json

@@ -22,7 +22,6 @@
     "webpack-cli": "^3.3.8",
     "webpack-dev-server": "^3.8.0"
   },
-  "homepage": "https://github.com/jonathan-grah/lofig",
   "license": "MIT",
   "main": "dist/lofig.min.js",
   "name": "lofig",
@@ -35,5 +34,5 @@
     "build": "webpack --mode=production",
     "test": "snyk test"
   },
-  "version": "1.2.0"
+  "version": "1.2.1"
 }

Some files were not shown because too many files changed in this diff