Saturday, October 24, 2020

Cache API in JavaScript

Cache API in Javascript


cache-api-in-javascript-by-visionfortech-pratik-soni
Cache API using JavaScript By Visionfortech

In this article i am going to show that how we can add,update,delete,retrive (CRUD operations) api urls and it's responses into cache so that our application will execute in more faster manner.

First step is we have to check weather our browser is supporting cache API or not. So now everyone will have a question like how we can check that ? So below is the answer for that.

Detect whether browser supports Cache API or not 

if ('caches' in window) {     // Means your browser is supporting cache API }else{ // Please upgrade your browser because cache APIs are not supported }


If your browser has suppor of cache API then let's go ahead and create cache

Create a Cache 

caches.open('visionfortech-cache').then(function(cacheInJS) { // It will return a promise and a object of cache which was either existed or created // before caches.open JS call });

Since we have created a cache now let's go ahead and try to add one or all URLs to cache.

Adding API URLs and it's response into Cache 

let URLs_to add = [ "/api/visionfortech_cache_api_Test1","api/visionfortech_cache_api2"]
let single_url = "api/visionfortech_cache_api1";

// Adding a single URL to cache

caches.open('visionfortech-cache').then(function(cacheInJS) { cacheInJS.add(single_url ); // URL will be fetched and cached });

// Adding multiple URL to cache

caches.open('visionfortech-cache').then(function(cacheInJS) { cacheInJS.addAll(URLs_to add) .then(function() { // Multiple URLs will be fetched and cached }); });



Since we have created a cache and added some URLs now let's go ahead and try to update the response of particular URL's response.

Update response of URL into Cache

fetch('api/visionfortech_cache_api1').then(function(response) { return caches.open('visionfortech-cache').then(function(cacheInJS) { return cacheInJS.put('api/visionfortech_cache_api1', response);
    // It will update the response for api/visionfortech_cache_api1 URL.
}); });

Till now we have seen how to create a cache and how to add API URLs and it's responses and how to update API response into Cache in case of change. So now let's go ahead and look at how we can retrieve the URLs which are cached and it's respective reponse object.


Retrive URLs and it's response from Cache

// Retrieve API URLs from cache like how many APIs we have stored in cache

caches.open('visionfortech-cache').then(function(cacheInJS) { cacheInJS.keys().then(function(cached_requests) { console.log(cached_requests); // It will return array of cache API URLs }); });

// Retrieve particular API response from Cache

caches.open('visionfortech-cache').then(function(cacheInJS) { cacheInJS.match('api/visionfortech_cache_api1').then(function(response) { console.log(response); }); });

So Now let's see how we can delete/clear our cache.

Delete a Cache 

caches.delete('visionfortech-cache').then(function(cacheInJS) {
// It will delete/clear the visionfortech-cache });


Hope you enjoyed the article and it got added something new to your knowledge.
To Learn more about Javascript Javascript Treasure.
To add something new every-time into your mind stay tuned to visionfortech.


Saturday, October 10, 2020

Speech to Text using Javascript

Speech to text using JavaScript



In this article i am going to show that how we can convert speech to text using JavaScript with it's browser API.

As you seen in above image, the output/outcome of this example/program is user will be able to get spoken words into text/string and his/her confidence level(in %) while speaking those words.

with the user of inbuilt web api of browser we can achieve above program,we can recognize speech using JavaScript. It is very easy to recognize speech in a browser using JavaScript and then getting the text from the speech to use as user input. We havecovered How to convert Text to Speech using Javascript.

Want to download source code ? : Speech-to-text-using-Javascript


We have used the SpeechRecognition object. We haven't used too many properties. We have a simple HTML webpage in the example, where we have a button control to initiate the speech recognition action.


Output of this Application : 




Note: It will work only in Google Chrome browser
While running the code into the browser will ask for permission to use your Microphone, so please click on Allow and then speak anything to see the program in action.
Hope you enjoyed the article and it got added something new to your knowledge.
To Learn more about Javascript Javascript Treasure.
To add something new every-time into your mind stay tuned to visionfortech.

Enjoy......!!!
Happy Learning.....!!!

Saturday, May 30, 2020

Face Recognition using JavaScript

Face recognition using JavaScript


Into this article i am going to describe How we can calculate age, gender detection, and his/her expression by just detecting his/he face.

Surprised. I was too.... Now face detection is possible using java script which is one of the most common applications of Artificial Intelligence

code structure of face recognition using javascript : By visionfortech

In Javascript world face-api.js came up with JavaScript API for face detection and face recognition in the browser implemented on top of the tensorflow.js core APIs

Want to download source code ? : face-recognition-using-javascript


Output of this Application : 

code structure of face recognition using javascript : By visionfortech


In this article we will provide the information that how we can detect expression of a human being, Age of a person and his/her Gender

Below will be the project structure.

code structure of face recognition using javascript : By visionfortech


Or You can download the code from face-recognition-using-javascript

Hope you enjoyed the article and it got added something new to your knowledge.
To Learn more about Javascript Javascript Treasure.
To add something new every-time into your mind stay tuned to visionfortech.

Enjoy......!!!
Happy Learning.....!!!

Sunday, March 29, 2020

Steps to update Angular from Angular 8 to Angular 9

Update application from Angular 8 -> Angular 9


Though we have angular9 released so in this article i would like to discuss how we can update our Angular App from Angular8 to Angular 9. In other words i would like to say Migrate existing angular application to angular9 from angular8

To know what are the new features into Angular 9 Angular 9 Features.

So to upgrade it to angular 9 follow below steps.


  • Make sure you will have node version 10.13 or later version. I would advice use latest version that is Node 12.
  • Make sure you will have your angular-cli at 8 ( You can check angular version by ng --version command).
  • After that update your angular-cli to latest version using ng update @angular/cli
  • After upgradation of angular-cli please update your angular/core package using ng update @angular/core command
  • Now you can check that you will have angular9 installed using ng--version.
Hope you enjoyed the article and it got added something new to your knowledge.
To Learn more about Javascript Javascript Treasure.
To add something new every-time into your mind stay tuned to visionfortech.

Enjoy......!!!
Happy Learning.....!!!

Saturday, March 21, 2020

Top New Features introduced into Angular 9 / What's majorly new in Angular 9

what's new into Angular 9 or Features into Angular 9




If you would like to know the features or new things which got introduced into Angular 9 then you are at the right place. Here into this article we are going to discuss what are the new things got introduced into Angular 9 or what are the features got introduced into Angular 9

Angular Features

  1. Default Ivy Compiler
  2. Smaller Bundles and Performance
  3. Typescript 3.7 Support
  4. Service Worker Updates
  5. Enables the AOT compiler on by default
  6. i18n Improvements
  7. Need for Faster Mobile Apps
  8. Changes with Angular Forms
  9. Dependency Injection Changes in Core
  10. Lazy load Angular components
  11. Angular Component Updates
  12. API Extractor Updates


Default Ivy Compiler

The more awaited very big new feature Ivy compiler is available  default for Angular 9, which will make sure to make your angular apps built with Ivy are faster and more efficient. So user won't require to add any compiler options in tsconfig.json file to enable Ivy like Angular 8.


Smaller Bundles and Performance

Into Angular 9 IVY complier make sure that you Angular Application production bundle will have lower size in result we can faster build generation and the performance for the same application will get increased


Service Worker Updates

In current version of Angular 9, for service workers the deprecated versioned files option in the service worker asset group config has been removed. This means that your new ngsw-config.json file that looked like below file:
"assetGroups": [
{ "name": "visionfortech", "resources": { "versionedFiles": [ "/**/*.txt" ] } } ]

will now look something like below

"assetGroups": [
{ "name": "visionfortech", "resources": { "files": [ "/**/*.txt" ] } } ]


i18n Improvements

Angular a JavaScript framework is supporting internationalization, and with the Angular CLI you can generate standard codes that will help create translator files so that your angular application can be published in multiple languages. This process has been even further refactored by the Angular team on Ivy to make it easier by adding compile-time inlining.

Changes with Angular Forms

Into Angular 9 there are some more changes related to Angular Form. First change is <ngForm></ngForm> is no longer supported for Angular Form instead you need to use <ng-form></ng-form>.Second, the FormsModule.withConfig is no longer supported instead you have to use FormsModule directly.


Angular Component Updates


There is an upgrade for the @angular/cdk on Hammer.js, which allows to include gesture support and was needed if you chose to use the CDK. It's possible now. You can import it with this below command optionally:

import "HammerModule" from [@angular/platform-browser]


Dependency Injection Changes in Core

The new version of Angular has minor improved for dependency injections. This is not a big change but some support.functionality has been added for the providedIn value section of dependency injections.

@Injectable({ providedIn: 'platform' })  class VisionfortechService {...}
  1. Platform : Specifying providedIn: 'platform' makes the service available on a special singleton platform injector that is used by all applications on the page.
  2. Any : Provides a unique instance in each module (including lazy modules) that injects the token.


Enables the AOT(Ahead-of-time) compiler on by default

In the current IVY architecture, we see a so many changes in the compiler's performance. This means that the AOT(Ahead-of-time) builds will be noticeably faster. The change in the compiler and runtime, will no longer require entryComponents. and ng serve. These components in latest version of Angular 9 will compile automatically depending on their usage.



Need for Faster Mobile Apps

Now a days mobile usage is rapidly growing around the quarter of the website traffic is made up of phones and other mobile devices. Some percentage of these mobile devices is going to access web pages from slow internet connections. Its important to decrease downloadable resources and increase mobile user experience,to get that Ivy helps in speed application startup by reducing the size of JavaScript classes.

Hope you enjoyed the article and it got added something new to your knowledge.
To Learn more about Javascript Javascript Treasure.
To add something new every-time into your mind stay tuned to visionfortech.

Enjoy......!!!
Happy Learning.....!!!

Friday, February 21, 2020

[Solution] Invoking generator for vue-cli-plugin-nativescript-vue... ERROR Error: Cannot find module '@vue/cli-service/generator/template/src/main.js'

[Solution] Invoking generator for vue-cli-plugin-nativescript-vue... ERROR Error: Cannot find module '@vue/cli-service/generator/template/src/main.js'

visionfortech nativescript-vue

If you are facing "Invoking generator for vue-cli-plugin-nativescript-vue... ERROR Error: Cannot find module '@vue/cli-service/generator/template/src/main.js" error while working with vue-cli-nativescriot-vue plugin So you are at the correct place.

I have found a solution for the same and below is the solution.

Please follow below steps to get it resolved.
Please remove npm and npm-cache folder from your computer's below location.
Windows :
C:\Users\AppData\Roaming.
Linux/Ubuntu:
/usr/local
Then Follow below steps
1) npm install -g @vue/cli@3.10.0
2) Go to code sharing project Directory's root folder location where you have package.json
3)npm install --save-dev @vue/cli-service@3.5.0
4)npm install --save-dev vue-cli-plugin-nativescript-vue@0.0.12
5)vue invoke vue-cli-plugin-nativescript-vue
 after that it will ask you for some user input and i provided below inputs.
? Enter a unique application identifier: org.nativescript.application
? Use HTML5 history mode? (Default: hash mode) No
? Is this a brand new project? (Default: Yes) Yes
? Dual Native AND Web development experience or a Native only? (Default: Dual) Dual Native AND Web
? What type of template do you want to start with? (Default: Simple) Simple.

So by following above steps you will be able to resolve the above error..

If anyone is still facing the same issue please comment that into the post i will happy to help them to get that resolved.
Hope you enjoyed the article and it got added something new to your knowledge.
To add something new every-time into your mind stay tuned to visionfortech.

Enjoy......!!!
Happy Learning.....!!!

Thursday, January 24, 2019

Angularjs forms and models

forms and models


now into review i want to insert a review form to get review from users so lets start to insert form into review tab

Into the form of review tab we are going get how much starts user want to give for our product and what are the reviews and what author gives the review.i want all above information.

Into HTML
<form name="reviewForm>
<blockquote>
<b>Stars : {{review.stars}}</b>
{{review.body}}
<author>by : {{review.author}}</author>
</blockquote>
<select ng-model="review.stars">
<option value="1">1 Star </option>
<option value="2">2 Star </option>
<option value="3">3 Star </option>
<option value="4">4 Star </option>
<option value="5">5 Star </option>
</select>
<textarea ng-model="review.body"></textarea>
<label>by : </label>
<input ng-model="review.author" type="email" />
</form>

so in above code we can't define review variable anywhere so better coding prctise we need to define that so for that we need to intialize that and commonly intialization can be done into the controller so lets create the Controller.

App.js
app.controller("reviewController",function(){
this.review={}
});

So,now we need to bind this review Controller into our form so for that we need to do the Following.

Into HTML

<form name="reviewForm ng-controller="reviewController as reviewCtrl">
<blockquote>
<b>Stars : {{review.stars}}</b>
{{reviewCtrl.review.body}}
<author>by : {{reviewCtrl.review.author}}</author>
</blockquote>
<select ng-model="reviewCtrl.review.stars">
<option value="1">1 Star </option>
<option value="2">2 Star </option>
<option value="3">3 Star </option>
<option value="4">4 Star </option>
<option value="5">5 Star </option>
</select>
<textarea ng-model="reviewCtrl.review.body"></textarea>
<label>by : </label>
<input ng-model="reviewCtrl.review.author" type="email" />
</form>

So after filling needed information we need to submit the form and into Angular we have a ng-submit directive

ng-submit allows us to call a function when the form is submitted and after that we need to define that function into our ReviewController.

So into HTML :

<form name="reviewForm ng-controller="reviewController as reviewCtrl" ng-submit="reviewCtrl .addReview(product)">
<blockquote>
<b>Stars : {{review.stars}}</b>
{{reviewCtrl.review.body}}
<author>by : {{reviewCtrl.review.author}}</author>
</blockquote>
<select ng-model="reviewCtrl.review.stars">
<option value="1">1 Star </option>
<option value="2">2 Star </option>
<option value="3">3 Star </option>
<option value="4">4 Star </option>
<option value="5">5 Star </option>
</select>
<textarea ng-model="reviewCtrl.review.body"></textarea>
<label>by : </label>
<input ng-model="reviewCtrl.review.author" type="email" />
</form>

So now we have to define this addReview function into ReviewController.

So Into app.js

app.controller("ReviewController",function(){

this.review={};

this.addReview=function(product)
{
product.review.push(this.review);
};
});

But when we went to browser and input our review and after submitting the form container which has all the input controller are not getring blank or we can say resetted so for that we just need to add one line into the addReview function of reviewController.

So Into app.js

app.controller("ReviewController",function(){

this.review={};

this.addReview=function(product)
{
product.review.push(this.review);
this.review={};
};
});

So what it can do is when this form is getting submitted and when this function got called so after pushing review into array we can assign a new javascript object to the review object which is blank.So after getting submitted the element's values will get reset.

form
1)You need to create multiple li's for each review that exists.
2)Set the blockquote stars ( strong tag) to the review stars.
3)Add the review body between the strong & cite tags.
4)Set the cite to the review author.
5)Use ng-model for review.stars select form field.
6)Use ng-model for review.body for the forms textarea.
7)Use ng-model for review.author – the email field.
8)In the strong tag, before Stars, put in the right expression to display review.stars. Keep the space prior to Stars
9)On the blank line with no tags put in the right expression to display review.body
10)In the cite tag, immediately after the -, put in the right expression to display review.author. 

Tuesday, October 16, 2018

Javascript JSON to string

Javascript JSON to string


Into this post we are going to discuss how to convert Javascript JSON ( Javascript Object Notation ) to string or javascript json to string.

Into this kind real IT world we can say Javascript is everywhere like front end and BackEnd both so we can say Javascript is going to rule everywhere.

Javascript JSON to String by visionfortech , Javascript blog

So in today's article we are going to discuss JSON which generally uses to pass data from one end to another end.

Let start understanding of that using below simple examples.

So into Javascript we can do that easily using JSON.stringify().

First let's take and example of Object

let json_to_string = JSON.stringify({ javascript_json: 5, json_to_string: 6 })

console.log(json_to_string);

//output: "{"javascript_json":5,"json_to_string":6}"
Now let's take an example of run time creation of Array of Object

let json_to_string = JSON.stringify([new String('visiofortech'),new Boolean(false),new Number(7)])

console.log(json_to_string);

//output: "["visiofortech",false,7}"
Now let's take an example of Date object

let json_to_string = JSON.stringify(new Date(2018, 10, 16, 15, 4, 5))

console.log(json_to_string);

//output: ""2018-11-16T09:34:05.000Z""

Hope you enjoyed the article and it got added something new to your knowledge.
To add something new every-time into your mind stay tuned to visionfortech.

To Learn more about Javascript Javascript Treasure.

Please comment below if you have something doubts or some questions.

Enjoy...!!!
Happy Learning....!!!

Thursday, September 13, 2018

Javascript Global and Local Variables

Javascript Global and Local Variables


Into this post we are going to discuss difference between how to declare javascript global variable and javascript local variable and its scope

we are going to discuss how can we declare global variable and local varible into Javascript with example.

Javascript global variable vs local variable by visionfortech
Javascript global variable vs local variable by visionfortech


Javascript Global Variable:

If we define var and let variable same globally then let variable will not get added into global window object while var variable will get added to global window object.

So let's declare two variables at the time of window loaded
let Visionfortech_global = "Visionfortech is defined as Global variable"

var Visionfortech_local = "Visionfortech is defined as Local variable"

console.log(Visionfortech_global);
o/p : undefined

console.log(Visionfortech_local);
o/p : Visionfortech is defined as Local variable
  

Javascript Local Variable : 
let js_local_variable = 1;

if (js_local_variable === 1) {
  let js_local_variable = 2;

  console.log(js_local_variable);
  // output: 2
}

console.log(js_local_variable);
// output: 1
  

Now let see the scope example of Javascript global and Local variable.

var global_variable = 1;
var javascript_global_variable = 2;
if (a === 1) {
var global_variable = 11; // the scope is global
let javascript_global_variable = 22; // the scope is inside the if-block
console.log(global_variable); // 11
console.log(javascript_global_variable); // 22
}
console.log(global_variable); // 11
console.log(javascript_global_variable); // 2

Enjoy....!!!!

Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

Friday, August 10, 2018

Javascript let vs var


Javascript Let vs Var


Into this post we are going to discuss difference between Javascript var and Let.

we are going to discuss about Javascipt variable declaration method like where user can declare variable with var and where user can declare variable with let.



Global Variable Declaration:

If we define var and let variable same globally then let variable will not get added into global window object while var variable will get added to global window object.

So let's declare two variables at the time of window loaded
let Visionfortech_let = "Visionfortech is defined as let variable"

var Visionfortech_var = "Visionfortech is defined as var variable"

console.log(Visionfortech_let);
o/p : undefined

console.log(Visionfortech_var);
o/p : Visionfortech is defined as var variable
  

Redeclare Variable:


So Here let's discuss about one more example of let vs var into Javascript.You can not declare let variable but you can redeclare var variable


'use strict';
var let_vs_var = "Javascript let vs var";
var let_vs_var = "Difference Between let and var Javascript"; //replaced easily
'use strict';
let let_vs_var = "Javascript let vs var";
let let_vs_var = "Difference Between let and var Javascript"; // Error: let_vs_var is already declared

Javascript Let Example : 
let vision = 1;

if (vision === 1) {
  let vision = 2;

  console.log(vision);
  // output: 2
}

console.log(vision);
// output: 1
  

Now let see the scope example of Javascript let vs var.

var let_vs_var = 1;
var javascript_var = 2;
if (a === 1) {
var let_vs_var = 11; // the scope is global
let javascript_var = 22; // the scope is inside the if-block
console.log(let_vs_var); // 11
console.log(javascript_var); // 22
}
console.log(let_vs_var); // 11
console.log(javascript_var); // 2

Enjoy....!!!!

Feel free to comment below your experience with above approach and If you still find any problem  with above steps Let me know I would love to help you to resolve your  problem.

 If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech

Protected by Copyscape