<commit_before>(function _LongDescriptor_s_() {

'use strict';

let _global = _global_;
let _ = _global.wTools;
let Self = _global.wTools;

_.assert( !_.Array );
_.assert( !_.defaultLong );
_.assert( !_.withDefaultLong );

// --
//
// --

function make_functor( name, cls )
{
  _.assert( arguments.length === 2 );
  _.assert( _.routineIs( cls ) );
  _.assert( _.strDefined( cls.name ) );
  // let r = /* Dmytro : maybe, it's better Implementation, it takes into account quantity of arguments and its type */
  // {
  //   [ name ] : function( src )
  //   {
  //     _.assert( arguments.length === 0 || arguments.length === 1 );
  //
  //     if( src === undefined || src === null )
  //     src = 0;
  //
  //     _.assert( _.numberIs( src ) || _.longIs( src ) );
  //     return new cls( src );
  //   }
  // }
  let r =
  {
    [ name ] : function()
    {
      return new cls( ... arguments );
    }
  }
  return r[ name ];
}

//

function from_functor( name, cls )
{
  _.assert( arguments.length === 2 );
  _.assert( _.routineIs( cls ) );
  _.assert( _.strDefined( cls.name ) );
  let r =
  {
    [ name ] : function( src )
    {
      _.assert( arguments.length === 0 || arguments.length === 1 );
      if( src === undefined )
      return new cls()
      if( this instanceof cls )
      return this;
      return new cls( src );
    }
  }
  return r[ name ];
}

//

function is_functor( name, cls )
{
  _.assert( arguments.length === 2 );
  _.assert( _.routineIs( cls ) );
  _.assert( _.strDefined( cls.name ) );
  let r =
  {
    [ name ] : function( src )
    {
      /* aaa : cover please */
      /* Dmytro : covered */
      _.assert( arguments.length === 1 );
      return src instanceof cls;
    }
  }
  return r[ name ];
}

//

function _longDeclare( o )
{

  o = Object.assign( Object.create( null ), o );
  for( let k in _longDeclare.defaults )
  if( !( k in o ) )
  o[ k ] = _longDeclare.defaults[ k ];

  _.assert( _.strDefined( o.name ) );
  _.assert( _.strDefined( o.secondName ) || o.secondName === null );
  _.assert( _.strDefined( o.aliasName ) || o.aliasName === null );
  _.assert( _.routineIs( o.type ) );
  _.assert( _.routineIs( o.make ) || o.make === null );
  _.assert( _.routineIs( o.from ) || o.from === null );
  _.assert( _.routineIs( o.is ) || o.make === null );
  _.assert( _.boolIs( o.isTyped ) );
  _.assert( LongDescriptors[ o.name ] === undefined );

  if( !o.make )
  o.make = make_functor( o.name, o.type );
  /* qqq : cover please _.longDescriptor.make */

  if( !o.from )
  o.from = from_functor( o.name, o.type );
  /* qqq : cover please _.longDescriptor.from */

  if( !o.is )
  o.is = is_functor( o.name, o.type );
  /* aaa : cover please _.longDescriptor.is */
  /* Dmytro : covered */

  Object.freeze( o );
  LongDescriptors[ o.name ] = o;
  if( !LongTypeToDescriptorsHash.get( o.type ) )
  LongTypeToDescriptorsHash.set( o.type, o );

  return o;
}

_longDeclare.defaults =
{
  name : null,
  secondName : null,
  aliasName : null,
  type : null,<commit_msg>Fix routine `from_functor`, replace `this` -> `src` to check src instance<commit_after>(function _LongDescriptor_s_() {

'use strict';

let _global = _global_;
let _ = _global.wTools;
let Self = _global.wTools;

_.assert( !_.Array );
_.assert( !_.defaultLong );
_.assert( !_.withDefaultLong );

// --
//
// --

function is_functor( name, cls )
{
  _.assert( arguments.length === 2 );
  _.assert( _.routineIs( cls ) );
  _.assert( _.strDefined( cls.name ) );
  let r =
  {
    [ name ] : function( src )
    {
      /* aaa : cover please */
      /* Dmytro : covered */
      _.assert( arguments.length === 1 );
      return src instanceof cls;
    }
  }
  return r[ name ];
}

//

function make_functor( name, cls )
{
  _.assert( arguments.length === 2 );
  _.assert( _.routineIs( cls ) );
  _.assert( _.strDefined( cls.name ) );
  // let r = /* Dmytro : maybe, it's better Implementation, it takes into account quantity of arguments and its type */
  // {
  //   [ name ] : function( src )
  //   {
  //     _.assert( arguments.length === 0 || arguments.length === 1 );
  //
  //     if( src === undefined || src === null )
  //     src = 0;
  //
  //     _.assert( _.numberIs( src ) || _.longIs( src ) );
  //     return new cls( src );
  //   }
  // }
  let r =
  {
    [ name ] : function()
    {
      return new cls( ... arguments );
    }
  }
  return r[ name ];
}

//

function from_functor( name, cls )
{
  _.assert( arguments.length === 2 );
  _.assert( _.routineIs( cls ) );
  _.assert( _.strDefined( cls.name ) );
  let r =
  {
    [ name ] : function( src )
    {
      // _.assert( arguments.length === 1 ); /* Dmytro : assertion for single argument is better for from routine */
      // _.assert( _.longIs( src ) || _.numberIs( src ) || src === undefined || src === null ); /* Dmytro : maybe, it is missed, if src is any map, then returns empty buffer */
      _.assert( arguments.length === 0 || arguments.length === 1 );
      if( src === undefined )
      return new cls()
      // if( this instanceof cls )
      // return this;
      if( src instanceof cls )
      return src;
      return new cls( src );
    }
  }
  return r[ name ];
}

//

function _longDeclare( o )
{

  o = Object.assign( Object.create( null ), o );
  for( let k in _longDeclare.defaults )
  if( !( k in o ) )
  o[ k ] = _longDeclare.defaults[ k ];

  _.assert( _.strDefined( o.name ) );
  _.assert( _.strDefined( o.secondName ) || o.secondName === null );
  _.assert( _.strDefined( o.aliasName ) || o.aliasName === null );
  _.assert( _.routineIs( o.type ) );
  _.assert( _.routineIs( o.make ) || o.make === null );
  _.assert( _.routineIs( o.from ) || o.from === null );
  _.assert( _.routineIs( o.is ) || o.make === null );
  _.assert( _.boolIs( o.isTyped ) );
  _.assert( LongDescriptors[ o.name ] === undefined );

  if( !o.is )
    o.is = is_functor( o.name, o.type );
  /* aaa : cover please _.longDescriptor.is */
  /* Dmytro : covered */

  if( !o.make )
  o.make = make_functor( o.name, o.type );
  /* aaa : cover please _.longDescriptor.make */
  /* Dmytro : covered */

  if( !o.from )
  o.from = from_functor( o.name, o.type );
  /* qqq : cover please _.longDescriptor.from */
  /* Dmytro : covered, needs clarification of a few features */

  Object.freeze( o );
  LongDescriptors[ o.name ] = o;
  if( !LongTypeToDescriptorsHash.get( o.type ) )
  LongTypeToDescriptorsHash.set( o.type, o );

  return o;
}

_longDeclare.defaults =
{
  name : null,
  secondName : null,
  aliasName : null,
  type : null,
{'fraction_non_alphanumeric': 0.17699386503067485, 'fraction_numerical': 0.002914110429447853, 'mean_word_length': 2.316887080366226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2000240', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2333, 'n_words': 602}