ywfts is a package that gives you some cool features, like database and some tools you can use that can help your life. It was created to be as simple yet as full of features as possible. The source code is public so you can see any time! The database is json based by the way.
to access the database, we are using the Database
class, that gives us all of the functions about the database
const ywfts = require("ywfts.js")
const db = new ywfts.Database('Name is optional!')
<db>
is what you defined as ywfts.Database()
-
<db>.set(key, value)
will set a specific value to the key, keep in mind this key as you will use it everytime you want to access that key's value -
<db>.get(key)
will get the value for this specific key, if there is no value, it will returnundefined
-
<db>.add(key, value)
will add a value to a key, only works with numbers and STRINGS ONLY CONTAINING NUMBERS. -
<db>.subtract(key, value)
Subtracts a specific value from the key's value -
<db>.delete(key)
will delete the key from the database -
<db>.clear()
will clear the entire database for you -
<db>.push(key, value)
will push the value to an array stored in the key, if there is no value on the key, it will set the key's value an array with only the value inside. -
<db>.removeFromArray(key, value)
will remove from that key's array a specific value, so you don't have to. -
<db>.readAll()
will return the entire file's data. Everything. -
<db>.addGitIgnore()
will add the database's file name to a .gitignore file, if there is already one, it will overwrite the content aslastcontent + new line + database file
This will set bread
with a value of 500
and then will print the value of bread
db.set("bread", 500)
console.log(db.get("bread"))
{"bread": 500 }
500
This will add to our past key bread
a value of 100
db.add("bread", 100)
console.log(db.get("bread"))
{"bread": 600}
600
this will push the string 'This is a string'
to an array, now there is no array on the key's value yet, so the database will create one for with that value already.
db.push("myArray", 'This is a string')
console.log(db.get("myArray"))
{"myArray": ["This is a string"]}
['This is a string']
everytime you run this, it will add the same string to the array.
this will remove from our past key myArray
the string This is a string
, but when we remove the only string from the array, all we have left is an empty array like []
, however if you ran 2 times the code, you noticed there is 2 of the same strings on the array, so in that case, it would remove the first one, leaving you with only ['This is a string']
array.
db.removeFromArray("myArray", 'This is a string')
console.log(db.get("myArray"))
{"myArray": []}
[]
let's delete the item rock
and read our current database, after that, we are going to clear the entire database and check how it looks
db.delete("rock")
console.log(db.readAll())
db.clear()
console.log(db.readAll())
before deleting "rock"
{"anotherrock": 500, "rock": "Not dwayne the rock johnson"}
after deleting "rock"
{"anotherrock": 500}
after clearing the database
{}
{"anotherrock": 500}
{}
even though this is not the main reason this package exists, there is 3 current tools that can be usefull in case you don't want to create a custom function just to make a specific task.
Almost the same as database, but instead we just need to replace it with Tools, like this:
const ywfts = require("ywfts.js")
const tools = new ywfts.Tools()
there are no extra options for tools btw.
<tools>
is what you defined as ywfts.Tools()
-
<tools>.removeFromObject(object, value)
Removes a specific value from the object -
<tools>.removeFromArray(array, value)
Removes a specific value frmo the array -
<tools>.calcOnString(number1, operation, number2)
Works when you need to calculate numbers inside strings like'100' + '200'
, because normally this would return100200
and not300
, but with this method it does return300
let's have the array [200, 400, 100, 50]
and we want to have only an array with the values of [200, 100, 50]
, which means we have to remove the 400
.
let array = [200, 400, 100, 50]
tools.removeFromArray(array, 400)
console.log(array)
[ 200, 100, 50 ]
let's say we have the object { "name": "something", "bread": true }
and we want ONLY bread
to be on the object
let obj = { "name": "something", "bread": true }
tools.removeFromObject(obj, 'name')
console.log(obj)
{ "bread": true }
ok so we have the strings '100'
and '200'
and we want to add only the numbers inside, so instead of '100200'
we want 300
to be the output
console.log(tools.calcOnString('100', '+', '200'))
300
- Big change on the setup
- Bug fixes on some functions.
- Fixed readme.md
- Bug Fixed! (icon was too big)
- Removed the object "value", so now it consumes less space, but the same efficency
- You can now GET a value of a key inside an object inside a key, something like this:
db.get("myObject.something")
{"myObject": { "something": "myValue" }}
- There is now complete support for objects, so now you can set stuff directly on an object inside a key, like this:
db.set('myObject.myParam', 10)
{"myObject": {"myParam": 10}}
- Fixed subtract function error, where it would create a new key and not subtract the value at all.
- Fixed error messages and readme, also saw that ywfts is on yarn so added to links the yarn package link
well, with some of these examples and some creativity, you can create some cool stuff! if you have any error, bug or any ideia you want to share, please join our discord server!