Socket
Socket
Sign inDemoInstall

@ckeditor/ckeditor5-word-count

Package Overview
Dependencies
Maintainers
1
Versions
601
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckeditor/ckeditor5-word-count - npm Package Compare versions

Comparing version 10.0.1 to 10.0.2

lang/translations/da.po

14

CHANGELOG.md
Changelog
=========
## [10.0.2](https://github.com/ckeditor/ckeditor5-word-count/compare/v10.0.1...v10.0.2) (2019-08-26)
### Bug fixes
* Improve words recognition, remove enter from counted characters. Closes [#4](https://github.com/ckeditor/ckeditor5-word-count/issues/4). Closes [#5](https://github.com/ckeditor/ckeditor5-word-count/issues/5). ([7e7ee48](https://github.com/ckeditor/ckeditor5-word-count/commit/7e7ee48))
* Word count plugin no longer throws an error when a container is undefined. Closes [#16](https://github.com/ckeditor/ckeditor5-word-count/issues/16). ([e1a7a7e](https://github.com/ckeditor/ckeditor5-word-count/commit/e1a7a7e))
### Other changes
* The issue tracker for this package was moved to https://github.com/ckeditor/ckeditor5/issues. See [ckeditor/ckeditor5#1988](https://github.com/ckeditor/ckeditor5/issues/1988). ([f8035d1](https://github.com/ckeditor/ckeditor5-word-count/commit/f8035d1))
* Made `WordCount#characters` and `WordCount#words` getters synchronous to make it possible to retrieve precise content stats on demand. Closes [#6](https://github.com/ckeditor/ckeditor5-word-count/issues/6). ([780dfbf](https://github.com/ckeditor/ckeditor5-word-count/commit/780dfbf))
* Updated translations. ([9aab7fb](https://github.com/ckeditor/ckeditor5-word-count/commit/9aab7fb))
## [10.0.1](https://github.com/ckeditor/ckeditor5-word-count/compare/v10.0.0...v10.0.1) (2019-07-10)

@@ -5,0 +19,0 @@

30

package.json
{
"name": "@ckeditor/ckeditor5-word-count",
"version": "10.0.1",
"description": "Word count feature for CKEditor 5.",
"version": "10.0.2",
"description": "Word count and character count features for CKEditor 5.",
"keywords": [

@@ -13,17 +13,17 @@ "ckeditor",

"dependencies": {
"@ckeditor/ckeditor5-core": "^12.2.1",
"@ckeditor/ckeditor5-ui": "^13.0.2",
"@ckeditor/ckeditor5-core": "^12.3.0",
"@ckeditor/ckeditor5-ui": "^14.0.0",
"lodash-es": "^4.17.10"
},
"devDependencies": {
"@ckeditor/ckeditor5-basic-styles": "^11.1.3",
"@ckeditor/ckeditor5-block-quote": "^11.1.2",
"@ckeditor/ckeditor5-editor-classic": "^12.1.3",
"@ckeditor/ckeditor5-engine": "^13.2.1",
"@ckeditor/ckeditor5-enter": "^11.0.4",
"@ckeditor/ckeditor5-link": "^11.1.1",
"@ckeditor/ckeditor5-list": "^12.0.4",
"@ckeditor/ckeditor5-paragraph": "^11.0.4",
"@ckeditor/ckeditor5-table": "^13.0.2",
"@ckeditor/ckeditor5-utils": "^13.0.1",
"@ckeditor/ckeditor5-basic-styles": "^11.1.4",
"@ckeditor/ckeditor5-block-quote": "^11.1.3",
"@ckeditor/ckeditor5-editor-classic": "^12.1.4",
"@ckeditor/ckeditor5-engine": "^14.0.0",
"@ckeditor/ckeditor5-enter": "^11.1.0",
"@ckeditor/ckeditor5-link": "^11.1.2",
"@ckeditor/ckeditor5-list": "^12.1.0",
"@ckeditor/ckeditor5-paragraph": "^11.0.5",
"@ckeditor/ckeditor5-table": "^14.0.0",
"@ckeditor/ckeditor5-utils": "^14.0.0",
"eslint": "^5.5.0",

@@ -41,3 +41,3 @@ "eslint-config-ckeditor5": "^2.0.0",

"homepage": "https://ckeditor.com",
"bugs": "https://github.com/ckeditor/ckeditor5-word-count/issues",
"bugs": "https://github.com/ckeditor/ckeditor5/issues",
"repository": {

@@ -44,0 +44,0 @@ "type": "git",

@@ -1,2 +0,2 @@

CKEditor 5 word count feature
CKEditor 5 word count and character count feature
===========================

@@ -13,7 +13,7 @@

This package implements word count support for CKEditor 5.
This package implements word count and character count support for CKEditor 5.
## Demo
Check out the demo in the [Word count feature](https://ckeditor.com/docs/ckeditor5/latest/features/word-count.html) guide.
Check out the demo in the [Word count and character count feature](https://ckeditor.com/docs/ckeditor5/latest/features/word-count.html) guide.

@@ -20,0 +20,0 @@ ## Documentation

@@ -14,3 +14,3 @@ /**

* @param {module:engine/model/element~Element} element
* @returns {String} Plain text representing model's data
* @returns {String} Plain text representing the model's data.
*/

@@ -17,0 +17,0 @@ export function modelElementToPlainText( element ) {

@@ -15,2 +15,3 @@ /**

import Template from '@ckeditor/ckeditor5-ui/src/template';
import env from '@ckeditor/ckeditor5-utils/src/env';

@@ -21,9 +22,9 @@ /**

* This plugin calculates all words and characters in all {@link module:engine/model/text~Text text nodes} available in the model.
* It also provides an HTML element, which updates its states whenever the editor's content is changed.
* It also provides an HTML element that updates its state whenever the editor content is changed.
*
* Firstly model's data are convert to plain text using {@link module:word-count/utils.modelElementToPlainText}.
* Based on such created plain text there are determined amount of words and characters in your text. Please keep in mind
* that every block in the editor is separate with a newline character, which is included in the calculation.
* The model's data is first converted to plain text using {@link module:word-count/utils.modelElementToPlainText}.
* The number of words and characters in your text are determined based on the created plain text. Please keep in mind
* that every block in the editor is separated with a newline character, which is included in the calculation.
*
* Few examples of how word and character calculation are made:
* Here are some examples of how the word and character calculations are made:
*

@@ -73,4 +74,20 @@ * <paragraph>foo</paragraph>

// Don't wait for the #update event to set the value of the properties but obtain it right away.
// This way, accessing the properties directly returns precise numbers, e.g. for validation, etc.
// If not accessed directly, the properties will be refreshed upon #update anyway.
Object.defineProperties( this, {
characters: {
get() {
return ( this.characters = this._getCharacters() );
}
},
words: {
get() {
return ( this.words = this._getWords() );
}
}
} );
/**
* Label used to display words value in {@link #wordCountContainer output container}
* The label used to display the words value in the {@link #wordCountContainer output container}.
*

@@ -85,3 +102,3 @@ * @observable

/**
* Label used to display characters value in {@link #wordCountContainer output container}
* The label used to display the characters value in the {@link #wordCountContainer output container}.
*

@@ -96,3 +113,3 @@ * @observable

/**
* The configuration of this plugins.
* The configuration of this plugin.
*

@@ -105,3 +122,3 @@ * @private

/**
* A reference to a {@link module:ui/view~View view object} which contains self-updating HTML container.
* The reference to a {@link module:ui/view~View view object} that contains the self-updating HTML container.
*

@@ -113,2 +130,20 @@ * @private

this._outputView;
/**
* A regular expression used to recognize words in the editor's content.
*
* @readonly
* @private
* @type {RegExp}
*/
this._wordsMatchRegExp = env.features.isRegExpUnicodePropertySupported ?
// Usage of regular expression literal cause error during build (ckeditor/ckeditor5-dev#534).
// Groups:
// {L} - Any kind of letter from any language.
// {N} - Any kind of numeric character in any script.
// {M} - A character intended to be combined with another character (e.g. accents, umlauts, enclosing boxes, etc.).
// {Pd} - Any kind of hyphen or dash.
// {Pc} - A punctuation character such as an underscore that connects words.
new RegExp( '[\\p{L}\\p{N}\\p{M}\\p{Pd}\\p{Pc}]+', 'gu' ) :
/[_\-a-zA-Z0-9À-ž]+/gu;
}

@@ -129,3 +164,3 @@

editor.model.document.on( 'change:data', throttle( this._calculateWordsAndCharacters.bind( this ), 250 ) );
editor.model.document.on( 'change:data', throttle( this._refreshStats.bind( this ), 250 ) );

@@ -147,4 +182,6 @@ if ( typeof this._config.onUpdate == 'function' ) {

destroy() {
this._outputView.element.remove();
this._outputView.destroy();
if ( this._outputView ) {
this._outputView.element.remove();
this._outputView.destroy();
}

@@ -155,4 +192,4 @@ super.destroy();

/**
* Creates self-updated HTML element. Repeated executions return the same element.
* Returned element has followed HTML structure:
* Creates a self-updating HTML element. Repeated executions return the same element.
* The returned element has the following HTML structure:
*

@@ -231,18 +268,40 @@ * <div class="ck ck-word-count">

/**
* Determines the number of words and characters in the current editor's model and assigns it to {@link #characters} and {@link #words}.
* It also fires {@link #event:update}.
* Determines the number of characters in the current editor's model.
*
* @private
* @fires update
* @returns {Number}
*/
_calculateWordsAndCharacters() {
_getCharacters() {
const txt = modelElementToPlainText( this.editor.model.document.getRoot() );
this.characters = txt.length;
return txt.replace( /\n/g, '' ).length;
}
this.words = ( txt.match( /[_a-zA-Z0-9À-ž]+/gu ) || [] ).length;
/**
* Determines the number of words in the current editor's model.
*
* @private
* @returns {Number}
*/
_getWords() {
const txt = modelElementToPlainText( this.editor.model.document.getRoot() );
const detectedWords = txt.match( this._wordsMatchRegExp ) || [];
return detectedWords.length;
}
/**
* Determines the number of words and characters in the current editor's model and assigns it to {@link #characters} and {@link #words}.
* It also fires the {@link #event:update}.
*
* @private
* @fires update
*/
_refreshStats() {
const words = this.words = this._getWords();
const characters = this.characters = this._getCharacters();
this.fire( 'update', {
words: this.words,
characters: this.characters
words,
characters
} );

@@ -253,8 +312,8 @@ }

/**
* Event fired after {@link #words} and {@link #characters} are updated.
* An event fired after {@link #words} and {@link #characters} are updated.
*
* @event update
* @param {Object} data
* @param {Number} data.words number of words in current model
* @param {Number} data.characters number of characters in current model
* @param {Number} data.words The number of words in the current model.
* @param {Number} data.characters The number of characters in the current model.
*/

@@ -287,11 +346,11 @@

/**
* This option allows for hiding the word count. The element obtained through
* This option allows for hiding the word counter. The element obtained through
* {@link module:word-count/wordcount~WordCount#wordCountContainer} will only preserve
* the characters part. word count is displayed by default when this configuration option is not defined.
* the characters part. Word counter is displayed by default when this configuration option is not defined.
*
* const wordCountConfig = {
* displayWords: false
* }
* };
*
* The mentioned configuration will result with the followed container:
* The configuration above will result in the following container:
*

@@ -312,5 +371,5 @@ * <div class="ck ck-word-count">

* displayCharacters: false
* }
* };
*
* The mentioned configuration will result in the following container
* The configuration above will result in the following container:
*

@@ -325,5 +384,5 @@ * <div class="ck ck-word-count">

/**
* This configuration takes a function, which is executed whenever the word-count plugin updates its values.
* This function is called with one argument, which is an object with `words` and `characters` keys containing
* a number of detected words and characters in the document.
* This configuration takes a function that is executed whenever the word count plugin updates its values.
* This function is called with one argument, which is an object with the `words` and `characters` keys containing
* the number of detected words and characters in the document.
*

@@ -335,3 +394,3 @@ * const wordCountConfig = {

* }
* }
* };
*

@@ -342,10 +401,10 @@ * @member {Function} module:word-count/wordcount~WordCountConfig#onUpdate

/**
* This option allows on providing an HTML element where
* {@link module:word-count/wordcount~WordCount#wordCountContainer word count container} will be appended automatically.
* Allows for providing the HTML element that the
* {@link module:word-count/wordcount~WordCount#wordCountContainer word count container} will be appended to automatically.
*
* const wordCountConfig = {
* container: document.getElementById( 'container-for-word-count' );
* }
* };
*
* @member {HTMLElement} module:word-count/wordcount~WordCountConfig#container
*/
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc