'use strict';

/**
 * A bundle of javascript prototypes extenders used by YDR.
 * 
 * @See See the documentation for each native javascript prototype handled here
 * 
 * @module @wider/utils_proto 
 * @copyright Copyright (C) 1985..2021 Martin Baker. http://y-d-r.co.uk
 * @author Martin W Baker
 * @license ISC Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * 
 */
import $wider from "@wider/registry";

import assignString from "./proto_string/index.js";
import assignArray from "./proto_array/index.js";
import assignFunction from "./proto_function/index.js";
import assignDate from "./proto_date/index.js";
import assignNumber from "./proto_number/index.js";
import assignObject from "./proto_object/index.js";

const $moduleName = "@wider/utils_proto";

/**
 * Initialises objects to support the features in this packages, delivering them as additional methods.  To minimise risk of name clashes all method names start ***wider_***
 * @method init
 * @param {Object} [settings] settings to control the way this operates.  Possible members are
 * 
 * *  **array** if this is ***false*** then the array features are not loaded, if ***null*** or is missing then the default **Array** object is extended, otherwise is your custom object to extend with array features.
 * 
 * 		If you use the false option to suppress an option, it may still be activated by a further call later
 * *  **string** likewise for the ***String*** object
 * *  **function** likewise for the ***Function*** object
 * *  **date** likewise for the ***Date*** object (do not confuse with ***$wider.Date***)
 * *  **number** likewise for the ***Number*** object
 * *  **object** likewise for the ***Object*** object
 * *  **markdown** if this is ***false*** ***null*** or is missing then ***markdown-it*** is not included in the ***String*** features.  If **true** then the default settings are used otherwise this is to be an object giving settings as per the *markdown-it* package documentation
 * @returns {Promise|void} if markdown is requested a **Promise** is returned.  The promise is fulfilled when the markdown extension is ready for use.  
 * @example
 * import { utils_proto } from "@wider/utils_proto"
 * utils_proto({markdown:true})
 * 	.then(()=>{console.log("ready")});
 */
export function utils_proto(settings = {}) {
	let result;

	if (settings.array !== false) assignArray(settings.array);
	if (settings.string !== false) result = assignString(settings.string, settings.markdown);
	if (settings.function !== false) assignFunction(settings.function);
	if (settings.date !== false) assignDate(settings.date);
	if (settings.number !== false) assignNumber(settings.number);
	if (settings.object !== false) assignObject(settings.object);

	return result;
}

utils_proto.$moduleName = $moduleName;
utils_proto.$moduleTitle = utils_proto.$moduleName + " - Preset extensions for standard javascript objects of your extensions thereof";

$wider.registry.register($moduleName, utils_proto, "proto", "utils");