How to use the object-path.ensureExists function in object-path

To help you get started, we’ve selected a few object-path examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Autodesk / clearx / src / store.js View on Github external
ensureExists (key, defaultValue) {
    let exists = this.has(key)
    if (!exists) {
      objectpath.ensureExists(this.data, key, defaultValue)
      this.handler.changed([key])
    }
  }
  // deletes a path
github wizawu / 1c / src / parser / parseClass.ts View on Github external
case "CONSTR":
                if (!ignore) buffer.push(item as never)
                break
            case "MEMBER":
                if (!ignore && item.name !== "prototype" && item.line.indexOf("constructor:") < 0) {
                    buffer.push(item as never)
                }
                break
            case "END":
                if (!ignore) {
                    if (!isInterface) buffer.push({ line: "    public static class: java.lang.Class" })
                    buffer.push(item as never)
                    let className = item.name.replace(/^(\w+\.)+/, "")
                    let classID = className.replace(/<.+$/, "")
                    let ns = item.name.substring(0, item.name.length - className.length - 1)
                    ensureExists(pkg, ns, {})
                    if (ns === "java.lang" && className === "Object") {
                        get(pkg, ns, {})[className] = "type Object = any"
                    } else {
                        // remove template arguments
                        let buffer0line = buffer[0].line, templateRegex = /<[^<>]+ extends/
                        while (buffer0line.search(templateRegex) >= 0) {
                            let openAngles = 1, start = buffer0line.search(templateRegex), end = 0
                            for (let i = start + 1; i < buffer0line.length; i++) {
                                if (buffer0line.charAt(i) === "<") {
                                    openAngles += 1
                                } else if (buffer0line.charAt(i) === ">") {
                                    openAngles -= 1
                                    if (openAngles === 0) {
                                        end = i + 1
                                        break
                                    }
github ibi-group / datatools-ui / lib / editor / components / timetable / TimetableEditor.js View on Github external
objectPath.set(newRow, `stopTimes.${i}.departureTime`, cumulativeTravelTime)
        objectPath.set(newRow, `stopTimes.${i}.timepoint`, stop.timepoint || 0)
        objectPath.set(newRow, `stopTimes.${i}.shapeDistTraveled`, stop.shapeDistTraveled)
        // Use pattern stop index to set stop sequence. Stop sequences should all
        // be zero-based and incrementing in the editor, but in the case that
        // they're not (e.g., due to a bad import) simply default to the index.
        objectPath.set(newRow, `stopTimes.${i}.stopSequence`, i)
        // }
      }
      for (let i = 0; i < this.props.columns.length; i++) {
        const col = this.props.columns[i]
        if (isTimeFormat(col.type)) {
          // TODO: add default travel/dwell times to new rows
          // objectPath.ensureExists(newRow, col.key, 0)
        } else {
          objectPath.ensureExists(newRow, col.key, null)
        }
      }
      // IMPORTANT: set id to NEW_ID
      objectPath.set(newRow, 'id', ENTITY.NEW_ID)
      objectPath.set(newRow, 'tripId', null)
      objectPath.set(newRow, 'useFrequency', activePattern.useFrequency)
      if (activePattern.useFrequency) {
        // If a frequency-based trip, never use exact times. NOTE: there is no
        // column to edit this field in the timetable grid.
        objectPath.set(newRow, 'frequencies.0.exactTimes', 0)
      } else {
        // If not using frequencies, set frequencies to empty array so that SQL backend
        // is happy.
        objectPath.set(newRow, 'frequencies', [])
      }
      // Set fields derived from pattern.
github mockoon / mockoon / src / app / libs / dummy-helpers.lib.ts View on Github external
body: function (path: string, defaultValue: string) {
      const requestContentType: string = request.header('Content-Type');

      if (typeof defaultValue === 'object') {
        defaultValue = '';
      }

      // try to parse body otherwise return defaultValue
      try {
        let value;

        if (requestContentType.includes('application/x-www-form-urlencoded')) {
          value = queryString.parse(request.body)[path];
        } else {
          const jsonBody = JSON.parse(request.body);
          value = objectPath.ensureExists(jsonBody, path);
        }

        if (value !== undefined) {
          return value;
        } else {
          return defaultValue;
        }
      } catch (e) {
        return defaultValue;
      }
    },
    // use params from url /:param1/:param2
github ibi-group / datatools-ui / lib / editor / components / timetable / TimetableEditor.js View on Github external
// }
        cumulativeTravelTime += +stop.defaultDwellTime
        // if (stop.timepoint === null || stop.timepoint) {
        objectPath.set(newRow, `stopTimes.${i}.departureTime`, cumulativeTravelTime)
        objectPath.set(newRow, `stopTimes.${i}.timepoint`, stop.timepoint || 0)
        objectPath.set(newRow, `stopTimes.${i}.shapeDistTraveled`, stop.shapeDistTraveled)
        objectPath.set(newRow, `stopTimes.${i}.stopSequence`, stop.stopSequence)
        // }
      }
      for (let i = 0; i < this.props.timetable.columns.length; i++) {
        const col = this.props.timetable.columns[i]
        if (isTimeFormat(col.type)) {
          // TODO: add default travel/dwell times to new rows
          // objectPath.ensureExists(newRow, col.key, 0)
        } else {
          objectPath.ensureExists(newRow, col.key, null)
        }
      }
      // IMPORTANT: set id to NEW_ID
      objectPath.set(newRow, 'id', ENTITY.NEW_ID)
      objectPath.set(newRow, 'tripId', null)
      objectPath.set(newRow, 'useFrequency', activePattern.useFrequency)
      if (activePattern.useFrequency) {
        // If a frequency-based trip, never use exact times. NOTE: there is no
        // column to edit this field in the timetable grid.
        objectPath.set(newRow, 'frequencies.0.exactTimes', 0)
      } else {
        // If not using frequencies, set frequencies to empty array so that SQL backend
        // is happy.
        objectPath.set(newRow, 'frequencies', [])
      }
      // Set fields derived from pattern.
github wizawu / 1c / src / compiler / parseClass.js View on Github external
else {
                        memberMap[item.name] = "    " + item.name + "(...args: any[]): any";
                    }
                }
                else {
                    memberMap[item.name] = item.line;
                }
                break;
            case "END":
                if (ignore)
                    break;
                Object.keys(memberMap).forEach(function (key) { return buffer.push(memberMap[key]); });
                buffer.push(item.line);
                var className = item.name.replace(/^(\w+\.)+/, "");
                var ns = item.name.substring(0, item.name.length - className.length - 1);
                object_path_1.ensureExists(pkg, ns, {});
                object_path_1.get(pkg, ns)[className] = buffer.join("\n");
                break;
            default:
                console.error(JSON.stringify(item));
                process.exit(const_1.EXIT_STATUS.PARSE_CLASS_ERROR);
        }
    };
    for (var i = 0; i < ctx.stack.length; i++) {
github mockoon / mockoon / src / app / classes / response-rules-interpreter.ts View on Github external
private isValidRule = (rule: ResponseRule): boolean => {
    if (!rule.modifier || !rule.target) {
      return false;
    }

    let value;

    if (rule.target === 'header') {
      value = this.request.header(rule.modifier);
    } else {
      value = objectPath.ensureExists(this.targets[rule.target], rule.modifier);
    }

    let regex: RegExp;
    if (rule.isRegex) {
      regex = new RegExp(rule.value);

      return Array.isArray(value)
        ? value.some(arrayValue => regex.test(arrayValue))
        : regex.test(value);
    }

    if (Array.isArray(value)) {
      return value.includes(rule.value);
    }

    return value === rule.value;
github wizawu / 1c / dist / parser / parseClass.js View on Github external
buffer.push(item);
                break;
            case "MEMBER":
                if (!ignore && item.name !== "prototype" && item.line.indexOf("constructor:") < 0) {
                    buffer.push(item);
                }
                break;
            case "END":
                if (!ignore) {
                    if (!isInterface)
                        buffer.push({ line: "    public static class: java.lang.Class" });
                    buffer.push(item);
                    var className = item.name.replace(/^(\w+\.)+/, "");
                    var classID = className.replace(/<.+$/, "");
                    var ns_1 = item.name.substring(0, item.name.length - className.length - 1);
                    object_path_1.ensureExists(pkg, ns_1, {});
                    if (ns_1 === "java.lang" && className === "Object") {
                        object_path_1.get(pkg, ns_1, {})[className] = "type Object = any";
                    }
                    else {
                        var buffer0line = buffer[0].line, templateRegex = /<[^<>]+ extends/;
                        while (buffer0line.search(templateRegex) >= 0) {
                            var openAngles = 1, start = buffer0line.search(templateRegex), end = 0;
                            for (var i_1 = start + 1; i_1 < buffer0line.length; i_1++) {
                                if (buffer0line.charAt(i_1) === "<") {
                                    openAngles += 1;
                                }
                                else if (buffer0line.charAt(i_1) === ">") {
                                    openAngles -= 1;
                                    if (openAngles === 0) {
                                        end = i_1 + 1;
                                        break;