Skip to content

dygy/dygytalLib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DygytalLib

A library of some basic functions, that not exist this easy way right now in JavaScript.
It has Node and Pure JS implementation, they are just a bit different.
To install you need to put in your console npm i @upgradle/dygytallib
let's see how to use it at pure.

<script src="@upgradle/dygytallib/pure/dygytal"> </script> 
<script> 
write('24'.reverse.toInt()+5) // 47 
</script> 

And now on node.

const methods = require('@upgradle/dygytallib/node/dygytal');
methods.write('23'.reverse);

Now let's see one method by one.

allEqual

after selecting an array or set, you can return boolean true or false, if every one of elem are same.

let arr= [];
arr.push(1);
arr.push(2);
write(arr.allEqual); //false

reverse

reversing string of integer. Even the float numbers. Can be helpful at information security.
You may reverse MD5 on both server and client, so it won't be easy to understan.

let int=125.39;
write(int.reverse);//39.521

replaceAll(value)

replacing all elements that equal to the given value.

let str = 'hello'
write(str.replaceAll('l','2')) //he22o

deleteAll(value)

deleting all elements that equal to the given value.

[1,1,2,1,3,1].deleteAll(1) //[2,3]

deleteIndex(index)

deleting element from array with given index.
[1,2,3].deleteIndex(0)//[2,3]

deleteElementFromLeft(value)

deleting first element from left, from array with given value.
[1,2,3,1].deleteElementFromLeft(1) // [2,3,1]

deleteElementFromRight(value)

deleting first element from right, from array with given value.
[1,2,3,1].deleteElementFromRight(1) // [1,2,3]

elem(index)

returning the element from set with given index.

let set= new Set();
set.add(1);
set.add(2);
write(set.elem(1)); //2

write(_)

writing a value as console.log , but if the value undefiend, than printing stack trace,
that's not breaking programm, but showing exact line of Undefiend.
It can be used like this in Pure js

write(undefined);
// Trace: Undefiend!
//     at write (C:\Users\yukim\WebstormProjects\dygytalLib\pure\dygytal.js:68:17)
//     at Object.<anonymous> (C:\Users\yukim\WebstormProjects\dygytalLib\pure\dygytal.js:162:1)
//     at Module._compile (internal/modules/cjs/loader.js:702:30)
//     at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
//     at Module.load (internal/modules/cjs/loader.js:612:32)
//     at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
//     at Function.Module._load (internal/modules/cjs/loader.js:543:3)
//     at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
//     at startup (internal/bootstrap/node.js:238:19)
//     at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)

And like this in node

require('./node_modules/dygytalLib/node/dygytal').write(undefined);

getURL()

returning current URL value.
Working only for Pure, as you can't get URL of Node js.

write(getURL) //printing your curent URL

insert(index)

returning array with inserted one more value before given index.

arr.insert(1,[])
write(arr)//[ 1, [], 2 ]

toInt()

returning integer from given string.
let num = '35'.toInt()+5 // 40

findFieldByName(json,fieldName)

returning a value from JSON by given name

let jason = {
    Cool:{
        Age:0,
        Sage:1
    },
    NotCool:{
        Name:'',
        Flame:'',
        Arr:[2,2,[1],{Name:'Lol'},1]
    }
};
write(findFieldByName(jason ,'Arr'));  //[ '2', '2', [ '1' ], { Name: 'Lol' }, '1' ]

includesBoth()

returning bool, is every string in arguments where included.
'aaa bbb'.includesBoth('aaa', 'bbb') //true'

isJson()

returning variable, if it is available to become JSON after parse .
'{}'.isJson() //{}'

SafeStorage

use it same as localstorage for getItem, setItem, removeItem, last argument is options - you can put here local property to select error langs (ru, en, es) it provides ability to don't check local storage permission and instructions to end user, how to enable it in browser.

About

A library of some basic functions, that wasn't exist right now in JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published