Sha256: e6210bf7a54b78db7b849ea4a2ba609260867a5d453e78dac0e9dcc42386ca7c

Contents?: true

Size: 1.32 KB

Versions: 10

Compression:

Stored size: 1.32 KB

Contents

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/

"use strict";

const formatPosition = (pos) => {
	if(pos === null)
		return "";
	const typeOfPos = typeof pos;
	switch(typeOfPos) {
		case "string":
			return pos;
		case "number":
			return `${pos}`;
		case "object":
			if(typeof pos.line === "number" && typeof pos.column === "number")
				return `${pos.line}:${pos.column}`;
			else if(typeof pos.line === "number")
				return `${pos.line}:?`;
			else if(typeof pos.index === "number")
				return `+${pos.index}`;
			else
				return "";
		default:
			return "";
	}
};

const formatLocation = (loc) => {
	if(loc === null)
		return "";
	const typeOfLoc = typeof loc;
	switch(typeOfLoc) {
		case "string":
			return loc;
		case "number":
			return `${loc}`;
		case "object":
			if(loc.start && loc.end) {
				if(typeof loc.start.line === "number" && typeof loc.end.line === "number" && typeof loc.end.column === "number" && loc.start.line === loc.end.line)
					return `${formatPosition(loc.start)}-${loc.end.column}`;
				return `${formatPosition(loc.start)}-${formatPosition(loc.end)}`;
			}
			if(loc.start)
				return formatPosition(loc.start);
			return formatPosition(loc);
		default:
			return "";
	}
};

module.exports = formatLocation;

Version data entries

10 entries across 6 versions & 3 rubygems

Version Path
ilog-0.4.1 node_modules/webpack/lib/formatLocation.js
ilog-0.4.0 node_modules/webpack/lib/formatLocation.js
ilog-0.3.3 node_modules/webpack/lib/formatLocation.js
optimacms-0.4.3 spec/dummy/node_modules/@rails/webpacker/node_modules/webpack/node_modules/webpack/lib/formatLocation.js
optimacms-0.4.3 spec/dummy/node_modules/@rails/webpacker/node_modules/webpack/lib/formatLocation.js
optimacms-0.4.3 spec/dummy/node_modules/webpack/lib/formatLocation.js
optimacms-0.4.2 spec/dummy/node_modules/@rails/webpacker/node_modules/webpack/lib/formatLocation.js
optimacms-0.4.2 spec/dummy/node_modules/webpack/lib/formatLocation.js
optimacms-0.4.2 spec/dummy/node_modules/@rails/webpacker/node_modules/webpack/node_modules/webpack/lib/formatLocation.js
cortex-0.1.3 spec/dummy/node_modules/webpack/lib/formatLocation.js