Skip to main content

Posts

Showing posts from May, 2021

Web Crypto API - Node 16

  Experimental Web Crypto API The Web Crypto API is the newer more well defined version of the Crypto library for JavaScript. All of the new Web Crypto methods are available on the  subtle  interface. Many browsers used an interface called  Crypto  without having a specific specification. The Web Crypto API adds a standard to the  Crypto  library. import { webcrypto } from 'crypto' ; const { subtle } = webcrypto ; ( async function ( ) { const key = await subtle . generateKey ( { name : 'HMAC' , hash : 'SHA-256' , length : 256 } , true , [ 'sign' , 'verify' ] ) ; const digest = await subtle . sign ( { name : 'HMAC' } , key , 'I love node.js' ) ; console . log ( digest ) ; } ) ( ) ;

good practice - react project - array - switch - update object of array

  setListing((prevState: any) => { const todos = [...prevState.listingTodos] const newTodos = todos.map(todo => { return { ...todo, expanded: todo.tabValue === todoValue, } }) return { ...prevState, listingLoading: false , listingTodos: newTodos, } }) // bad practice const array = [ [ [ 'Shoaib Mehedi' ] ] ] array . forEach ( ( firstArr ) => { firstArr . forEach ( ( secondArr ) => { secondArr . forEach ( ( element ) => { console . log ( element ) ; } ) } ) } ) // good practice const array = [ [ [ 'Shoaib Mehedi' ] ] ] const getValuesOfNestedArray = ( element ) => { if ( Array . isArray ( element ) ) { return getValuesOfNestedArray ( element [ 0 ] ) } return element } getValuesOfNestedArray ( array ) const { role } = user const components = { ADMIN : AdminUser , ...