Your IP : 216.73.216.86


Current Path : /var/www/homesaver/www/bitrix/js/main/core/src/lib/extension/internal/
Upload File :
Current File : /var/www/homesaver/www/bitrix/js/main/core/src/lib/extension/internal/settings-collection.js

import Type from '../../type';
import convertPath from './convert-path';

export default class SettingsCollection
{
	constructor(options: {[key: string]: any} = {})
	{
		if (Type.isPlainObject(options))
		{
			Object.assign(this, options);
		}
	}

	get(path: string, defaultValue: any = null)
	{
		const convertedPath = convertPath(path);

		return convertedPath.reduce((acc, key) => {
			if (!Type.isNil(acc) && acc !== defaultValue)
			{
				if (!Type.isUndefined(acc[key]))
				{
					return acc[key];
				}

				return defaultValue;
			}

			return acc;
		}, this);
	}
}