How to use object-path - 10 common examples

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 wessberg / ts-evaluator / src / interpreter / lexical-environment / lexical-environment.ts View on Github external
export function setInLexicalEnvironment ({env, path, value, reporting, node, newBinding = false}: ISetInLexicalEnvironmentOptions): void {
	const [firstBinding] = path.split(".");
	if (has(env.env, firstBinding) || newBinding || env.parentEnv == null) {
		// If the value didn't change, do no more
		if (has(env.env, path) && get(env.env, path) === value) return;

		// Otherwise, mutate it
		set(env.env, path, value);

		// Inform reporting hooks if any is given
		if (reporting.reportBindings != null && !isInternalSymbol(path)) {
			reporting.reportBindings({path, value, node});
		}
	}

	else {
		let currentParentEnv: LexicalEnvironment|undefined = env.parentEnv;
		while (currentParentEnv != null) {
			if (has(currentParentEnv.env, firstBinding)) {
github luisgustavolf / react-satisfying-forms / dev / src / react-satisfying-forms / form.tsx View on Github external
Object.keys(state.fieldsStatus).forEach((key) => {
            if (key === fieldName || (includeChildren && key.indexOf(`${fieldName}.`) > -1))
                delete state.fieldsStatus[key]
        })
        
        const indexRegexp = /\.(\d{1,})$/
        
        // Verify if its a array prop
        if (indexRegexp.test(fieldName)) {
            let initialIndex = parseInt(fieldName.match(indexRegexp)![1])
            
            while(true) {
                const presProp = fieldName.replace(indexRegexp, `.${initialIndex}`);
                const nextProp = fieldName.replace(indexRegexp, `.${initialIndex + 1}`);
                
                if (!OPath.has(state, nextProp))
                    break
                
                OPath.set(state, presProp, OPath.get(state, nextProp))
                initialIndex++
            }
        }

        return state
    }
github iuap-design / bee.tinper.org / tinper-bee / bee-table / src / TableCell.js View on Github external
render() {
    const { record, indentSize, clsPrefix, indent,
            index, expandIcon, column ,fixed,showSum, bodyDisplayInRow,lazyStartIndex,lazyEndIndex} = this.props;
    const { dataIndex, render, fieldType, linkConfig, fontColor, bgColor } = column;
    let {className = ''} = column;

    let text = objectPath.get(record, dataIndex);
    let tdProps;
    let colSpan;
    let rowSpan,title;

    if (render && !showSum) {
      text = render(text, record, index);
      if (this.isInvalidRenderCellText(text)) {
        tdProps = text.props || {};
        rowSpan = (tdProps.rowSpan>lazyEndIndex && lazyEndIndex>5)?lazyEndIndex-index:tdProps.rowSpan;
        colSpan = tdProps.colSpan;
        text = text.children;
      }
    }

    let colMenu = this.renderColumnMenu(column.cellMenu, text, record, index);
    // 根据 fieldType 来渲染数据
github Atomic-Reactor / Reactium / .core / .cli / commands / reactium / component / index.js View on Github external
});

    if (output.redux === false) {
        Object.entries(input).forEach(([key, val]) => {
            switch (String(key).toLowerCase()) {
                case 'actions':
                case 'actiontypes':
                case 'reducers':
                case 'services':
                    output[key] = false;
                    break;
            }
        });
    }

    output.ID = op.get(output, 'ID', output.name);
    output.ID = decamelize(output.ID).toUpperCase();

    const dir = path.basename(output.destination).toLowerCase();
    if (dir !== output.name.toLowerCase()) {
        output.destination = path.join(output.destination, output.name);
    }

    // Set the style import statement
    if (output.stylesheet === true) {
        const stylesheetFile = path.normalize(
            path.join(output.destination, '_style.scss'),
        );

        const importString = output.inject.map(filepath =>
            path
                .relative(filepath, stylesheetFile)
github nasa / cumulus-dashboard / app / src / js / components / SubForm / sub-form.js View on Github external
update (id, payload) {
    setTimeout(() => this.hide(id), 200);
    const { value } = this.props;
    if (!payload) {
      delete value[id];
    } else {
      // use the `_id` property to set the payload,
      // to account for someone changing the name of the file.
      set(value, payload._id, payload);
      // if the old name doesn't match the new name,
      // delete the old name to avoid duplication.
      if (id !== payload._id) delete value[id];
    }
    this.props.onChange(this.props.id, value);
  }
}
github nasa / cumulus-dashboard / app / src / js / reducers / granules.js View on Github external
set(state, ['list', 'meta'], assignDate(data.meta));
      set(state, ['list', 'inflight'], false);
      set(state, ['list', 'error'], false);
      break;
    case GRANULES_INFLIGHT:
      set(state, ['list', 'inflight'], true);
      break;
    case GRANULES_ERROR:
      set(state, ['list', 'inflight'], false);
      set(state, ['list', 'error'], action.error);
      break;

    // basically a dummy query to get the meta object,
    // which contains the number of granules updated in the last hour.
    case RECENT_GRANULES:
      set(state, ['recent', 'data'], data.meta);
      set(state, ['recent', 'inflight'], false);
      break;
    case RECENT_GRANULES_INFLIGHT:
      set(state, ['recent', 'inflight'], true);
      break;
    case RECENT_GRANULES_ERROR:
      set(state, ['recent', 'inflight'], false);
      set(state, ['recent', 'error'], action.error);
      break;

    case GRANULE_REPROCESS:
      set(state, ['reprocessed', id, 'status'], 'success');
      set(state, ['reprocessed', id, 'error'], null);
      break;
    case GRANULE_REPROCESS_INFLIGHT:
      set(state, ['reprocessed', id, 'status'], 'inflight');
github ibi-group / datatools-ui / scripts / lint-messages.js View on Github external
}

        // determine what the message path is
        // if the first character is not ', it's a variable or a template string
        const firstChar = line[messageIndex + 14]
        if (firstChar === "'") {
          // found a parseable message, add some stats
          jsMessageCounts[filePath] = (jsMessageCounts[filePath] || 0) + 1

          // argument sent to this.messages is a static string, get the string
          // and add an entry to the foundMessages object
          const message = line.substring(
            messageIndex + 15,
            line.indexOf(firstChar, messageIndex + 16)
          )
          objectPath.set(foundMessages, `${curClass}.${message}`, true)
        } else {
          // argument sent to this.messages is a variable or string template
          // TODO: analyze some kind of comment outlining message possibilities
          addIssue(
            'dynamicMessageWithoutPossibilitiesComment',
            `unable to determine message object path from variable or template string in file '${filePath}' on line ${lineIdx}`
          )
        }
      }
    }
  })
github LeaPhant / skyblock-stats / lib.js View on Github external
async function getItems(base64){
    // API stores data as base64 encoded gzipped Minecraft NBT data
    let buf = Buffer.from(base64, 'base64');

    let data = await parseNbt(buf);
    data = nbt.simplify(data);

    let items = data.i;

    // Check backpack contents and add them to the list of items
    for(let [index, item] of items.entries()){
        if(objectPath.has(item, 'tag.display.Name') && (item.tag.display.Name.endsWith('Backpack') || item.tag.display.Name.endsWith('Itchy New Year Cake Bag'))){

            let keys = Object.keys(item.tag.ExtraAttributes);

            let backpackData;

            keys.forEach(key => {
                if(key.endsWith('backpack_data') || key == 'new_year_cake_bag_data')
                    backpackData = item.tag.ExtraAttributes[key];
            });

            if(!Array.isArray(backpackData))
                continue;

            let backpackContents = await getBackpackContents(backpackData);

            backpackContents.forEach(backpackItem => {
github wessberg / ts-evaluator / src / interpreter / lexical-environment / lexical-environment.ts View on Github external
// If the value didn't change, do no more
		if (has(env.env, path) && get(env.env, path) === value) return;

		// Otherwise, mutate it
		set(env.env, path, value);

		// Inform reporting hooks if any is given
		if (reporting.reportBindings != null && !isInternalSymbol(path)) {
			reporting.reportBindings({path, value, node});
		}
	}

	else {
		let currentParentEnv: LexicalEnvironment|undefined = env.parentEnv;
		while (currentParentEnv != null) {
			if (has(currentParentEnv.env, firstBinding)) {
				// If the value didn't change, do no more
				if (has(currentParentEnv.env, path) && get(currentParentEnv.env, path) === value) return;

				// Otherwise, mutate it
				set(currentParentEnv.env, path, value);

				// Inform reporting hooks if any is given
				if (reporting.reportBindings != null && !isInternalSymbol(path)) {
					reporting.reportBindings({path, value, node});
				}
				return;
			}
			else {
				currentParentEnv = currentParentEnv.parentEnv;
			}
		}
github LeaPhant / skyblock-stats / lib.js View on Github external
let speed = parseInt(split[1]);

                        if(!isNaN(speed))
                            item.stats.speed = speed;
                    }
                })
            }
        }

        // Add snow canon and blaster to weapons
        if(objectPath.has(item, 'tag.ExtraAttributes.id') && ['SNOW_CANNON', 'SNOW_BLASTER'].includes(item.tag.ExtraAttributes.id))
            item.type = 'bow';

        // Workaround for detecting item types if another language is set by the player on Hypixel
        if(objectPath.has(item, 'tag.ExtraAttributes.id') && item.tag.ExtraAttributes.id != 'ENCHANTED_BOOK'){
            if(objectPath.has(item, 'tag.ExtraAttributes.enchantments')){
                if('sharpness' in item.tag.ExtraAttributes.enchantments
                || 'crticial' in item.tag.ExtraAttributes.enchantments
                || 'ender_slayer' in item.tag.ExtraAttributes.enchantments
                || 'execute' in item.tag.ExtraAttributes.enchantments
                || 'first_strike' in item.tag.ExtraAttributes.enchantments
                || 'giant_killer' in item.tag.ExtraAttributes.enchantments
                || 'lethality' in item.tag.ExtraAttributes.enchantments
                || 'life_steal' in item.tag.ExtraAttributes.enchantments
                || 'looting' in item.tag.ExtraAttributes.enchantments
                || 'luck' in item.tag.ExtraAttributes.enchantments
                || 'scavenger' in item.tag.ExtraAttributes.enchantments
                || 'vampirism' in item.tag.ExtraAttributes.enchantments
                || 'bane_of_arthropods' in item.tag.ExtraAttributes.enchantments
                || 'smite' in item.tag.ExtraAttributes.enchantments)
                    item.type = 'sword';