Skip to content

Commit c9b7e6d

Browse files
authored
Merge pull request #62 from koddsson/es-module
Convert project to ES module
2 parents db6c3e3 + b8c970e commit c9b7e6d

File tree

6 files changed

+14113
-13302
lines changed

6 files changed

+14113
-13302
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.0.0 / 2023-07-21
2+
==================
3+
4+
* convert project to a ES Module
15

26
0.1.1 / 2013-12-30
37
==================

index.js

+26-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict';
2-
31
/* !
42
* Chai - pathval utility
53
* Copyright(c) 2012-2014 Jake Luer <[email protected]>
@@ -44,7 +42,7 @@
4442
* @api public
4543
*/
4644

47-
function hasProperty(obj, name) {
45+
export function hasProperty(obj, name) {
4846
if (typeof obj === 'undefined' || obj === null) {
4947
return false;
5048
}
@@ -73,19 +71,19 @@ function hasProperty(obj, name) {
7371
*/
7472

7573
function parsePath(path) {
76-
var str = path.replace(/([^\\])\[/g, '$1.[');
77-
var parts = str.match(/(\\\.|[^.]+?)+/g);
78-
return parts.map(function mapMatches(value) {
74+
const str = path.replace(/([^\\])\[/g, '$1.[');
75+
const parts = str.match(/(\\\.|[^.]+?)+/g);
76+
return parts.map((value) => {
7977
if (
8078
value === 'constructor' ||
8179
value === '__proto__' ||
8280
value === 'prototype'
8381
) {
8482
return {};
8583
}
86-
var regexp = /^\[(\d+)\]$/;
87-
var mArr = regexp.exec(value);
88-
var parsed = null;
84+
const regexp = /^\[(\d+)\]$/;
85+
const mArr = regexp.exec(value);
86+
let parsed = null;
8987
if (mArr) {
9088
parsed = { i: parseFloat(mArr[1]) };
9189
} else {
@@ -112,12 +110,12 @@ function parsePath(path) {
112110
*/
113111

114112
function internalGetPathValue(obj, parsed, pathDepth) {
115-
var temporaryValue = obj;
116-
var res = null;
113+
let temporaryValue = obj;
114+
let res = null;
117115
pathDepth = typeof pathDepth === 'undefined' ? parsed.length : pathDepth;
118116

119-
for (var i = 0; i < pathDepth; i++) {
120-
var part = parsed[i];
117+
for (let i = 0; i < pathDepth; i++) {
118+
const part = parsed[i];
121119
if (temporaryValue) {
122120
if (typeof part.p === 'undefined') {
123121
temporaryValue = temporaryValue[part.i];
@@ -149,13 +147,13 @@ function internalGetPathValue(obj, parsed, pathDepth) {
149147
*/
150148

151149
function internalSetPathValue(obj, val, parsed) {
152-
var tempObj = obj;
153-
var pathDepth = parsed.length;
154-
var part = null;
150+
let tempObj = obj;
151+
const pathDepth = parsed.length;
152+
let part = null;
155153
// Here we iterate through every part of the path
156-
for (var i = 0; i < pathDepth; i++) {
157-
var propName = null;
158-
var propVal = null;
154+
for (let i = 0; i < pathDepth; i++) {
155+
let propName = null;
156+
let propVal = null;
159157
part = parsed[i];
160158

161159
// If it's the last part of the path, we set the 'propName' value with the property name
@@ -169,7 +167,7 @@ function internalSetPathValue(obj, val, parsed) {
169167
tempObj = tempObj[part.i];
170168
} else {
171169
// If the obj doesn't have the property we create one with that name to define it
172-
var next = parsed[i + 1];
170+
const next = parsed[i + 1];
173171
// Here we set the name of the property which will be defined
174172
propName = typeof part.p === 'undefined' ? part.i : part.p;
175173
// Here we decide if this property will be an array or a new object
@@ -202,10 +200,10 @@ function internalSetPathValue(obj, val, parsed) {
202200
* @api public
203201
*/
204202

205-
function getPathInfo(obj, path) {
206-
var parsed = parsePath(path);
207-
var last = parsed[parsed.length - 1];
208-
var info = {
203+
export function getPathInfo(obj, path) {
204+
const parsed = parsePath(path);
205+
const last = parsed[parsed.length - 1];
206+
const info = {
209207
parent:
210208
parsed.length > 1 ?
211209
internalGetPathValue(obj, parsed, parsed.length - 1) :
@@ -249,8 +247,8 @@ function getPathInfo(obj, path) {
249247
* @api public
250248
*/
251249

252-
function getPathValue(obj, path) {
253-
var info = getPathInfo(obj, path);
250+
export function getPathValue(obj, path) {
251+
const info = getPathInfo(obj, path);
254252
return info.value;
255253
}
256254

@@ -287,15 +285,8 @@ function getPathValue(obj, path) {
287285
* @api private
288286
*/
289287

290-
function setPathValue(obj, path, val) {
291-
var parsed = parsePath(path);
288+
export function setPathValue(obj, path, val) {
289+
const parsed = parsePath(path);
292290
internalSetPathValue(obj, val, parsed);
293291
return obj;
294292
}
295-
296-
module.exports = {
297-
hasProperty: hasProperty,
298-
getPathInfo: getPathInfo,
299-
getPathValue: getPathValue,
300-
setPathValue: setPathValue,
301-
};

karma.conf.js

-94
This file was deleted.

0 commit comments

Comments
 (0)