<commit_before>var JsonPath = module.exports = {};

JsonPath.get = get;
JsonPath.set = set;
JsonPath.remove = remove;

function get(obj, path) {
	var keys = path.replace(/\/+/g,'/').replace(/\/$/, '').split('/');
	if (keys[0] == '#') { keys.shift(); }

	while (keys.length) {
		var key = keys.shift();

		if (obj === undefined) {
			break;
		}

		obj = obj[key];

	}

	return obj;
}

function set(obj, path, value) {
	var keys = path.replace(/\/+/g,'/').replace(/\/$/, '').split('/');
	if (keys[0] == '#') { keys.shift(); }
	if (!keys.length) { return value; }

	var result = obj;

	for (var idx = 0, c = keys.length; idx < c; idx++) {
		if (result === undefined) {
			break;
		}

		var key = keys[idx];

		if (c - idx > 1) {
			result = result[key];
			continue;
		}

		result[key] = value;
		return obj;
	}
}

function remove(obj, path) {
	var keys = path.replace(/\/+/g,'/').replace(/\/$/, '').split('/');
	if (keys[0] == '#') { keys.shift(); }
	if (!keys.length) { return undefined; }

	var result = obj;

	for (var idx = 0, c = keys.length; idx < c; idx++) {
		var key = keys[idx];

		if (result === undefined) {
			break;
		}

		if (c - idx > 1) {
			result = result[key];
			continue;
		}
<commit_msg>parser, default in get, fix extract with first slash without #<commit_after>var JsonPath = module.exports = {};

/**
 *
 */
var parser = {
	extract: extract,
	combine: combine
};

/**
 *
 */
JsonPath.parser = parser;
JsonPath.get = get;
JsonPath.set = set;
JsonPath.remove = remove;

/**
 *
 */
function extract(path) {
	var keys = path.replace(/\/+/g,'/').replace(/\/$/, '').split('/');
	if (keys[0] == '#' || keys[0] === '') { keys.shift(); }
	return keys;
}

/**
 *
 */
function combine(keys) {
	if (keys[0] != '#') { keys.unshift('#'); }
	var path = keys.join('/');
	return path;
}

/**
 *
 */
function get(obj, path, deflt) {
	var keys = parser.extract(path);

	while (keys.length) {
		var key = keys.shift();

		if (obj === undefined) {
			break;
		}

		obj = obj[key];

	}

	console.log(obj);

	return obj || deflt;
}

/**
 *
 */
function set(obj, path, value) {
	var keys = parser.extract(path);

	if (!keys.length) { return value; }

	var result = obj;

	for (var idx = 0, c = keys.length; idx < c; idx++) {
		if (result === undefined) {
			break;
		}

		var key = keys[idx];

		if (c - idx > 1) {
			result = result[key];
			continue;
		}

		result[key] = value;
		return obj;
	}
}

/**
 *
 */
function remove(obj, path) {
	var keys = parser.extract(path);

	if (!keys.length) { return undefined; }

	var result = obj;

	for (var idx = 0, c = keys.length; idx < c; idx++) {
		var key = keys[idx];

		if (result === undefined) {
			break;
		}

		if (c - idx > 1) {
			result = result[key];
			continue;
		}

{'fraction_non_alphanumeric': 0.22246696035242292, 'fraction_numerical': 0.005139500734214391, 'mean_word_length': 2.717598908594816, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6295825', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1031, 'n_words': 265}