Author Archives: vgorbic1

Plug in Modules in JavaScript

In JavaScript there is different types of modules. You have Common JS modules, that NodeJS uses by default without even using Bable transpiler. Also there is ES2015 modules with a different plugin syntax. Both are used to bring in modules which can be other JavaScript files, but you also can bring in modules that are installed with NPM.

Common JavaScript modules

Create a simple js file named ‘mymodule.js’:

// make everything in this file available for the other files
module.exports = {
  name: 'Vlad',
  email: 'test@test.com'
}

In the app file bring this module file in:

const person = require('./mymodule'); // no .js extension!
console.log(person.name);

If you bring in a node module into you app use this:

const person = require('express');

ES2015 JavaScript modules

A slightly different syntax is used for ES2015+:

export const person = { //this variable can be accessed from other files
  name: 'Vlad',
  email: 'test@test.com'
}

In the app file bring in this module:

import { person } from './mymodule';
console.log(person.name);

If you need to import several variables/functions from one file:

import * as mod from './mymodule';

Exporting default object

The module file:

const greeting = 'Hello';
export default greeting;

In the app use no curly braces:

import greeting from './mymodule';
console.log(greeting);

Calculate person’s age from the date of birth

To calculate a person’s age from the date of birth use vanilla JavaScript:

function Person(dob) {
  this.birthday = new Date(dob);
  this.calculateAge = function() {
    const difference = Date.now() - this.birthday.getTime();
    const ageDate = new Date(difference);
    return Math.abs(ageDate.getUTCFullYear() - 1970);
  }
}
const person = new Person('9-10-1990');
console.log(person.calculateAge());

arccom.org

Goal: Develop a website (child theme) for a non-profit organization. Use WordPress as a CMS for the site. Test and deploy the site on the company’s server.
Parent theme: Eggnews by ThemeEgg
Web technologies and tools used: HTML5, CSS, PHP, WordPress, WooCommerce, Photoshop
Release date: November, 2017
Project type: Contract work for American-Russian Chamber of Commerce of Minnesota.
www.arccom.org