Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Td/class syntax #21325

Draft
wants to merge 12 commits into
base: trunk
Choose a base branch
from
Next Next commit
Refactor classes to use newer syntax with class keyword
  • Loading branch information
FAMarfuaty authored and mhkuu committed Apr 17, 2024
commit 138b0b7e271ec417d13559cbb3f4398023021af4
2 changes: 1 addition & 1 deletion packages/js/src/insights/initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const createUpdater = () => {
* @returns {void}
*/
return () => {
const paper = Paper.parse( collectData() );
const paper = Paper.prototype.parse( collectData() );

runResearch( "readingTime", paper ).then( response => setEstimatedReadingTime( response.result ) );
runResearch( "getFleschReadingScore", paper ).then( response => {
Expand Down
163 changes: 84 additions & 79 deletions packages/yoastseo/src/languageProcessing/values/ProminentWord.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,95 @@
/**
* Represents a prominent word in the context of relevant words.
*
* @constructor
*
* @param {string} word The word.
* @param {string} [stem] The stem / base form of the word, defaults to the word.
* @param {number} [occurrences] The number of occurrences, defaults to 0.
*/
function ProminentWord( word, stem, occurrences ) {
this._word = word;
this._stem = stem ? stem : word;
this._occurrences = occurrences || 0;
}
*/
class ProminentWord {
/**
* Constructs Prominent word object.
*
* @constructor
*
* @param {string} word The word.
* @param {string} [stem] The stem / base form of the word, defaults to the word.
* @param {number} [occurrences] The number of occurrences, defaults to 0.
*/
constructor( word, stem, occurrences ) {
this._word = word;
this._stem = stem ? stem : word;
this._occurrences = occurrences || 0;
}

/**
* Sets the word.
*
* @param {string} word The word to set.
*
* @returns {void}.
*/
ProminentWord.prototype.setWord = function( word ) {
this._word = word;
};
/**
* Sets the word.
*
* @param {string} word The word to set.
*
* @returns {void}.
*/
setWord( word ) {
this._word = word;
}

/**
* Returns the word.
*
* @returns {string} The word.
*/
ProminentWord.prototype.getWord = function() {
return this._word;
};
/**
* Returns the word.
*
* @returns {string} The word.
*/
getWord() {
return this._word;
}

/**
* Returns the stem of the word.
*
* @returns {string} The stem.
*/
ProminentWord.prototype.getStem = function() {
return this._stem;
};
/**
* Returns the stem of the word.
*
* @returns {string} The stem.
*/
getStem() {
return this._stem;
}

/**
* Sets the number of occurrences to the word.
*
* @param {int} numberOfOccurrences The number of occurrences to set.
*
* @returns {void}.
*/
ProminentWord.prototype.setOccurrences = function( numberOfOccurrences ) {
this._occurrences = numberOfOccurrences;
};
/**
* Sets the number of occurrences to the word.
*
* @param {int} numberOfOccurrences The number of occurrences to set.
*
* @returns {void}.
*/
setOccurrences( numberOfOccurrences ) {
this._occurrences = numberOfOccurrences;
}

/**
* Returns the amount of occurrences of this word.
*
* @returns {number} The number of occurrences.
*/
ProminentWord.prototype.getOccurrences = function() {
return this._occurrences;
};
/**
* Returns the amount of occurrences of this word.
*
* @returns {number} The number of occurrences.
*/
getOccurrences() {
return this._occurrences;
}

/**
* Serializes the ProminentWord instance to an object.
*
* @returns {Object} The serialized ProminentWord.
*/
ProminentWord.prototype.serialize = function() {
return {
_parseClass: "ProminentWord",
word: this._word,
stem: this._stem,
occurrences: this._occurrences,
};
};
/**
* Serializes the ProminentWord instance to an object.
*
* @returns {Object} The serialized ProminentWord.
*/
serialize() {
return {
_parseClass: "ProminentWord",
word: this._word,
stem: this._stem,
occurrences: this._occurrences,
};
}

/**
* Parses the object to a ProminentWord.
*
* @param {Object} serialized The serialized object.
*
* @returns {ProminentWord} The parsed ProminentWord.
*/
ProminentWord.parse = function( serialized ) {
return new ProminentWord( serialized.word, serialized.stem, serialized.occurrences );
};
/**
* Parses the object to a ProminentWord.
*
* @param {Object} serialized The serialized object.
*
* @returns {ProminentWord} The parsed ProminentWord.
*/
parse( serialized ) {
return new ProminentWord( serialized.word, serialized.stem, serialized.occurrences );
}
}

export default ProminentWord;
61 changes: 31 additions & 30 deletions packages/yoastseo/src/scoring/taxonomyAssessor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { inherits } from "util";

import IntroductionKeywordAssessment from "./assessments/seo/IntroductionKeywordAssessment";
import KeyphraseLengthAssessment from "./assessments/seo/KeyphraseLengthAssessment";
import KeyphraseDensityAssessment from "./assessments/seo/KeywordDensityAssessment";
Expand Down Expand Up @@ -33,36 +31,39 @@ export const getTextLengthAssessment = function() {

/**
* Creates the Assessor used for taxonomy pages.
*
* @param {Researcher} researcher The researcher used for the analysis.
* @param {Object?} options The options for this assessor.
* @constructor
*/
const TaxonomyAssessor = function( researcher, options ) {
Assessor.call( this, researcher, options );
this.type = "taxonomyAssessor";
class TaxonomyAssessor extends Assessor {
/**
* Creates a new taxonomy assessor.
*
* @param {Researcher} researcher The researcher to use.
* @param {Object} options The assessor options.
*/
constructor( researcher, options ) {
super( researcher, options );

this._assessments = [
new IntroductionKeywordAssessment(),
new KeyphraseLengthAssessment(),
new KeyphraseDensityAssessment(),
new MetaDescriptionKeywordAssessment(),
new MetaDescriptionLengthAssessment(),
getTextLengthAssessment(),
new KeyphraseInSEOTitleAssessment(),
new PageTitleWidthAssessment(
{
scores: {
widthTooShort: 9,
},
}, true
),
new SlugKeywordAssessment(),
new FunctionWordsInKeyphrase(),
new SingleH1Assessment(),
];
};
this.type = "taxonomyAssessor";

inherits( TaxonomyAssessor, Assessor );
this._assessments = [
new IntroductionKeywordAssessment(),
new KeyphraseLengthAssessment(),
new KeyphraseDensityAssessment(),
new MetaDescriptionKeywordAssessment(),
new MetaDescriptionLengthAssessment(),
getTextLengthAssessment(),
new KeyphraseInSEOTitleAssessment(),
new PageTitleWidthAssessment(
{
scores: {
widthTooShort: 9,
},
}, true
),
new SlugKeywordAssessment(),
new FunctionWordsInKeyphrase(),
new SingleH1Assessment(),
];
}
}

export default TaxonomyAssessor;