notations

declaration
 notations 

var notations = {
  bracket: /^\[([\s\S]+)\][\.]?([\w\S]+)*/,
  dot: /\.[^.]/,
  spaces: /\s/
};

Notation

class
 new Notation() 

This class determines whether a
string is in phrase, bracket, or dot notation.

class Notation {
  constructor(str) {
      this._key = str;
    }

isBracket

method
 Notation.isBracket() 

Option name Type Description
str String

The string to determine.

return Boolean

Returns true if the string is in bracket notation.

Determines whether a string is in bracket notation

static isBracket(str) {
    let hasBracket = Notation.hasPattern(str, notations.bracket);
    let hasEscaped = str.indexOf('[\\') > -1;
    return hasBracket && !hasEscaped;
  }

isDot

method
 Notation.isDot() 

Option name Type Description
str String

The string to determine.

return Boolean

Returns true if the string is in dot notation.

Determines whether a string is in dot notation

static isDot(str) {
    let hasDot = Notation.hasPattern(str, notations.dot);
    let hasSpaces = Notation.hasPattern(str, notations.spaces);
    return hasDot && !hasSpaces;
  }

isPhrase

method
 Notation.isPhrase() 

Option name Type Description
str String

The string to determine.

return Boolean

Returns true if the string is in dot notation.

Determines whether a string is in dot notation

static isPhrase(str) {
    return !Notation.isBracket(str) && !Notation.isDot(str);
  }

parse

method
 Notation.prototype.parse() 

Returns the notation type based on the string.

parse() {
  if (Notation.isPhrase(this._key)) {
    return {
      type: 'phrase',
      key: this._key.indexOf('[\\') > -1 ?
        this._key.replace('\\', '') : this._key,
      seek: undefined
    };
  }
  if (Notation.isBracket(this._key)) {
    var result = notations.bracket.exec(this._key);
    return {
      type: 'bracket',
      key: result[1],
      seek: result[2]
    };
  }
  if (Notation.isDot(this._key)) {
    return {
      type: 'dot',
      key: this._key,
      seek: undefined
    };
  }
}
}

export default Notation;