<commit_before>//Config.js
//we have a basic controller object
const controller = {
  path: null,
  getUrl(id) {
    if(id && this.path.indexOf(':id') !== -1) {
      return this.path.replace(':id', id); //replace the placeholder with the id
    }
    else if(id && this.path.indexOf(':id') === -1){ //didnt expect id but received one
      throw new Error('did not expect id');
    }
    else if(!id && this.path.indexOf(':id') !== -1) { //expected id but didn't receive one
      throw new Error('expected id');
    }
    else {
      return this.path;
    }
  }
}

//factory for controllers
function createController(url) {
  return Object.assign(Object.create(controller), {url});
}

//now lets use it
const controllers = {
  users: createController('/users'),
  user: createController('/users/:id') //this one is expecting id
}

export default {controllers};

//index.js
import Config from './Config.js';

fetch(Config.controllers.user.getUrl(1)).then(res => console.log(res)); //get user with id 1
<commit_msg>Update factory.js<commit_after>//Config.js
//we have a basic controller object
const controller = {
  getUrl(id) {
    if(id && this.path.indexOf(':id') !== -1) {
      return this.path.replace(':id', id); //replace the placeholder with the id
    }
    else if(id && this.path.indexOf(':id') === -1){ //didnt expect id but received one
      throw new Error('did not expect id');
    }
    else if(!id && this.path.indexOf(':id') !== -1) { //expected id but didn't receive one
      throw new Error('expected id');
    }
    else {
      return this.path;
    }
  }
}

//factory for controllers
function createController(path) {
  return Object.assign(Object.create(controller), {path});
}

//now lets use it
const controllers = {
  users: createController('/users'),
  user: createController('/users/:id') //this one is expecting id
}

export default {controllers};

//index.js
import Config from './Config.js';

fetch(Config.controllers.user.getUrl(1)).then(res => console.log(res)); //get user with id 1

{'fraction_non_alphanumeric': 0.16452569169960474, 'fraction_numerical': 0.004940711462450593, 'mean_word_length': 3.2452830188679247, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7514563', 'n_tokens_mistral': 632, 'n_tokens_neox': 625, 'n_words': 189}