1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 09:23:13 +01:00

Replace replaceSubstringAtIndex with built-in String.replace

This commit is contained in:
Brett Sun 2016-06-13 16:46:12 +02:00
parent de571c7fab
commit ad2b7c223c
3 changed files with 3 additions and 15 deletions

View File

@ -4,7 +4,7 @@ import React from 'react';
import classnames from 'classnames';
import { AclInformationText } from '../../constants/acl_information_text';
import { replaceSubstringAtIndex, sanitize, intersectLists } from '../../utils/general';
import { intersectLists, sanitize } from '../../utils/general';
import { getLangText } from '../../utils/lang';
@ -45,7 +45,7 @@ let AclInformation = React.createClass({
return (
<p key={title}>
<span className="info">
{replaceSubstringAtIndex(info.slice(2), 's ', ' ')}
{info.slice(2).replace('s', '')}
</span>
<span className="example">
{' ' + example}

View File

@ -5,8 +5,6 @@ import React from 'react';
import Form from '../ascribe_forms/form';
import Property from '../ascribe_forms/property';
import { replaceSubstringAtIndex } from '../../utils/general';
let HistoryIterator = React.createClass({
propTypes: {
@ -18,7 +16,7 @@ let HistoryIterator = React.createClass({
// We want to get the capturing group without the quotes,
// which is why we access the match list at index 1 and not 0
const contractName = historicalEvent[1].match(/\"(.*)\"/)[1];
const historicalEventDescription = replaceSubstringAtIndex(historicalEvent[1], `"${contractName}"`, '');
const historicalEventDescription = historicalEvent[1].replace(`"${contractName}"`, '');
return (
<span>
{historicalEventDescription}

View File

@ -27,16 +27,6 @@ export function escapeHTML(s) {
return document.createElement('div').appendChild(document.createTextNode(s)).parentNode.innerHTML;
}
/**
* @param index, int, the starting index of the substring to be replaced
* @param character, substring to be replaced
* @returns {string}
*/
export function replaceSubstringAtIndex(baseString, substrToReplace, stringToBePut) {
let index = baseString.indexOf(substrToReplace);
return baseString.substr(0, index) + stringToBePut + baseString.substr(index + substrToReplace.length);
}
/**
* Extracts the user's subdomain from the browser's window.
* If no subdomain is found (for example on a naked domain), the default "www" is just assumed.