Skip to content

Create methods class #22

@idangoldman

Description

@idangoldman

A base class for any class to inherit from, filled with helpful getters, setters, and methods.

export default class Methods {
  get empty() {}
  get inspect() {}
  get not() {}
  get size() {}

  get isEmail() {}
  get isUrl() {}
  get isSecureUrl() {}
  get isDate() {}
  get isHEX() {}
  get isRGB() {}
  get isRGBA() {}
  get isHSL() {}
  get isHSLA() {}
  get isPhoneNumber() {}
  get isNumber() {}
  get isIP() {}

  fromJSON() {}
  toJSON() {}
  fromClipboard() {}
  toClipboard() {}

  toCamelCase() {}
  toSnakeCase() {}
  toKababCase() {}
  toHungarianCase() {}
  toPascalCase() {}
  toConstCase() {}
  remapKeys(case = 'camelCase') {}

  each(callback) {}
  where(condition, callback) {}
  remove(condition, callback) {}
  re(regularExpression, callback) {}
  sort(condition, callback) {}
}

Each

Loop method to iterate over an array or object.

method.each( callback( [iteratee], [index] ) );

class Fruits extends Methods {
  #locals = [];

  get defaults() {
    return this.#locals;
  }

  set defaults(globals = []) {
    this.#locals = globals;
  }

  constructor(...fruits) {
    this.defaults(fruits);
  }
}

let bucketOfFruits    = new Fruits('Tomato', 'Banana', 'Watermelon', 'Apple', 'Orange', 'Mangoe');
let inventoryOfFruits = new Fruits(
  { 'type': 'Apples', 'count': 59 },
  { 'type': 'Bananas', 'count': 34 },
  { 'type': 'Mangoes', 'count': 95 },
  { 'type': 'Oranges', 'count': 78 },
  { 'type': 'Tomatoes', 'count': 43 },
  { 'type': 'Watermelons', 'count': 20 }
);

bucketOfFruits.each((fruit) => {
  console.log(fruit);
});

inventoryOfFruits.each(({count, type}) => {
  console.log(`We have ${count} ${type}.`);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions