Skip to content

Instantly share code, notes, and snippets.

Math.floor(15.7784514 * 100) / 100
// Populates process.env from .env file
function config (options /*: ?DotenvConfigOptions */) /*: DotenvConfigOutput */ {
let dotenvPath = path.resolve(process.cwd(), '.env')
let encoding /*: string */ = 'utf8'
let debug = false
if (options) {
if (options.path != null) {
dotenvPath = options.path
}
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @remove-on-eject-end
'use strict';
const webpack = require('webpack');
const dotenv = require('dotenv');
const fs = require('fs'); // to check if the file exists
const path = require('path'); // to get the current path
module.exports = (env) => {
// Get the root path (assuming your webpack config is in the root of your project!)
const currentPath = path.join(__dirname);
// Create the fallback path (the production .env)
const webpack = require('webpack');
const dotenv = require('dotenv');
module.exports = () => {
// call dotenv and it will return an Object with a parsed key
const env = dotenv.config().parsed;
// reduce it to a nice object, the same as before
const envKeys = Object.keys(env).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(env[next]);
// remember to require this, because we DefinePlugin is a webpack plugin
const webpack = require('webpack');
// return a function from the config file
// the `env` variable will be a simple Object: { API_URL: 'http://localhost:8000' }
// it will contain all the environment variables (that we set in package.json) as key/value pairs
module.exports = (env) => {
// this object is our actual webpack config
return {
plugins: [
@Kevinwkd
Kevinwkd / removeDuplication.ts
Created June 25, 2020 11:29
This ts code snippet is for removing the duplication in an array
import { ICompareFunc } from '../interfaces/Util';
export const removeNonPrimitiveDuplicate = (arr: any[], compareFunc: ICompareFunc) => {
return arr.reduce((unique, item) => {
let duplicated: boolean = false;
for(const key in unique) {
if (compareFunc(unique[key], item)) {
duplicated = true;
break;
}
@Kevinwkd
Kevinwkd / compareObject.ts
Created June 23, 2020 13:04
object-value-compare
/**
* This function is from https://gist.github.com/nicbell/6081098 for purpose to compare whether
* two objects are value equal. Specially cater for nested object comparison
*
* For simple object comparison we can use:
* (a, b) => JSON.stringify(Object.entries(a).sort()) === JSON.stringify(Object.entries(b).sort())
*
* @param obj1 The object is being compared
* @param obj2 The object is being compared
*/
/*
* Angular 2 decorators and services
*/
import {Component} from '@angular/core';
/**
* Include ScopedSelectors css to be injected in the template
* Webpack will process this CSS in module mode
* See the webpack.config.js in the root folder
*/
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that