<commit_before>define(['knockout', 'underscore', 'viewmodels/widget', 'bindings/formattedNumber'], function (ko, _, WidgetViewModel) {
    /**
    * registers a text-widget component for use in forms
    * @function external:"ko.components".text-widget
    * @param {object} params
    * @param {number} params.value - the value being managed
    * @param {function} params.config - observable containing config object
    * @param {string} params.config().label - label to use alongside the text input
    * @param {string} params.config().placeholder - default text to show in the text input
    */


    var NumberWidget = function(params) {
        params.configKeys = ['placeholder', 'width', 'min', 'max', 'step', 'precision', 'prefix', 'suffix', 'defaultValue', 'format'];

        WidgetViewModel.apply(this, [params]);

        var self = this;

        this.updateVal = ko.computed(function(){
            if (self.value() !== null){
                var val = self.value();
                if (typeof self.min() === 'number') {
                    val = Number(val) < Number(self.min()) ? Number(self.min()) : Number(val);
                }

                if (typeof self.max() === 'number') {
                    val = Number(val) > Number(self.max()) ? Number(self.max()) : Number(val);
                }

                if (self.precision()) {
                    val = Number(val).toFixed(self.precision());
                }
                val = val.toString();
            }
            return val || self.value();
        }, self).extend({throttle: 600});

        this.value(this.updateVal());

        if (ko.isObservable(this.precision)) {
            var precisionSubscription = this.precision.subscribe(function(val){
                if (self.value() && val){
                    self.value(Number(self.value()).toFixed(val));
                }
            }, self);
            self.disposables.push(precisionSubscription);
        }
        self.disposables.push(this.updateVal);
    };
<commit_msg>Check if a value is null or undefined, re #6685<commit_after>define(['knockout', 'underscore', 'viewmodels/widget', 'bindings/formattedNumber'], function (ko, _, WidgetViewModel) {
    /**
    * registers a text-widget component for use in forms
    * @function external:"ko.components".text-widget
    * @param {object} params
    * @param {number} params.value - the value being managed
    * @param {function} params.config - observable containing config object
    * @param {string} params.config().label - label to use alongside the text input
    * @param {string} params.config().placeholder - default text to show in the text input
    */


    var NumberWidget = function(params) {
        params.configKeys = ['placeholder', 'width', 'min', 'max', 'step', 'precision', 'prefix', 'suffix', 'defaultValue', 'format'];

        WidgetViewModel.apply(this, [params]);

        var self = this;

        this.updateVal = ko.computed(function(){
            if (self.value() !== null && self.value() !== undefined) { //allow a value of 0 to pass
                var val = self.value();
                if (typeof self.min() === 'number') {
                    val = Number(val) < Number(self.min()) ? Number(self.min()) : Number(val);
                }

                if (typeof self.max() === 'number') {
                    val = Number(val) > Number(self.max()) ? Number(self.max()) : Number(val);
                }

                if (self.precision()) {
                    val = Number(val).toFixed(self.precision());
                }
                val = val.toString();
            }
            return val || self.value();
        }, self).extend({throttle: 600});

        this.value(this.updateVal());

        if (ko.isObservable(this.precision)) {
            var precisionSubscription = this.precision.subscribe(function(val){
                if (self.value() && val){
                    self.value(Number(self.value()).toFixed(val));
                }
            }, self);
            self.disposables.push(precisionSubscription);
        }
        self.disposables.push(this.updateVal);
    };

{'fraction_non_alphanumeric': 0.14898746383799422, 'fraction_numerical': 0.002651880424300868, 'mean_word_length': 2.0756115641215716, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3430920', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1074, 'n_words': 266}