1.7.1 • Published 5 months ago

@enonic/js-utils v1.7.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 months ago

JavaScript Utilities

A library of constants and functions that should work in any

  • typescript
  • ecmascript
  • javascript

The intention is that the library should not depend upon any node-module that doesn't work in at least these environments:

  • Enonic XP serverside code
  • Modern browser
  • Newest LTS version of Node

It should work in at least these frameworks:

  • React

Examples

DSL

import {storage} from '@enonic/js-utils';

const and = storage.query.dsl.and;
const bool = storage.query.dsl.bool;
const fulltext = storage.query.dsl.fulltext;
const ngram = storage.query.dsl.ngram;
const stemmed = storage.query.dsl.stemmed;

const fields = 'url^1.2,title^1.1,text';
const searchString = 'fun video';
const operator = 'OR';
const query = bool(and(
	fulltext(fields, searchString, operator),
	stemmed(fields, searchString, operator, 'no', 0.9),
	stemmed(fields, searchString, operator, 'en', 0.8),
	ngram(fields, searchString, operator, 0.7)
));
console.debug(JSON.stringify(query, null, 4));

/*
{
	"boolean": {
		"must": [
			{
				"boolean": {
					"should": [
						{
							"fulltext": {
								"fields": [
									"url"
								],
								"query": "fun video",
								"operator": "OR",
								"boost": 1.2
							}
						},
						{
							"fulltext": {
								"fields": [
									"title"
								],
								"query": "fun video",
								"operator": "OR",
								"boost": 1.1
							}
						},
						{
							"fulltext": {
								"fields": [
									"text"
								],
								"query": "fun video",
								"operator": "OR"
							}
						}
					]
				}
			},
			{
				"boolean": {
					"should": [
						{
							"stemmed": {
								"fields": [
									"url"
								],
								"query": "fun video",
								"operator": "OR",
								"language": "no",
								"boost": 1.08
							}
						},
						{
							"stemmed": {
								"fields": [
									"title"
								],
								"query": "fun video",
								"operator": "OR",
								"language": "no",
								"boost": 0.9900000000000001
							}
						},
						{
							"stemmed": {
								"fields": [
									"text"
								],
								"query": "fun video",
								"operator": "OR",
								"language": "no",
								"boost": 0.9
							}
						}
					]
				}
			},
			{
				"boolean": {
					"should": [
						{
							"stemmed": {
								"fields": [
									"url"
								],
								"query": "fun video",
								"operator": "OR",
								"language": "en",
								"boost": 0.96
							}
						},
						{
							"stemmed": {
								"fields": [
									"title"
								],
								"query": "fun video",
								"operator": "OR",
								"language": "en",
								"boost": 0.8800000000000001
							}
						},
						{
							"stemmed": {
								"fields": [
									"text"
								],
								"query": "fun video",
								"operator": "OR",
								"language": "en",
								"boost": 0.8
							}
						}
					]
				}
			},
			{
				"boolean": {
					"should": [
						{
							"ngram": {
								"fields": [
									"url"
								],
								"query": "fun video",
								"operator": "OR",
								"boost": 0.84
							}
						},
						{
							"ngram": {
								"fields": [
									"title"
								],
								"query": "fun video",
								"operator": "OR",
								"boost": 0.77
							}
						},
						{
							"ngram": {
								"fields": [
									"text"
								],
								"query": "fun video",
								"operator": "OR",
								"boost": 0.7
							}
						}
					]
				}
			}
		]
	}
};
*/

Filter

import {addQueryFilter} from '@enonic/js-utils';

const filters = addQueryFilter({
	filter: {
		exists: {
			field: 'required'
		}
	}
});
/*{
	boolean: {
		must: {
			exists: {
				field: 'required'
			}
		}
	}
}*/

Release

git tag vX.Y.Z
git push origin vX.Y.Z

This will trigger release & publish on NPM.

1.6.1

6 months ago

1.6.0

6 months ago

1.5.4

6 months ago

1.5.3

7 months ago

1.5.2

7 months ago

1.5.1

7 months ago

1.5.0

8 months ago

1.4.1

8 months ago

1.7.1

5 months ago

1.7.0

5 months ago

1.3.1

8 months ago

1.3.0

8 months ago

1.2.0

9 months ago

1.0.0

12 months ago

0.46.0

12 months ago

1.1.1

9 months ago

1.1.0

10 months ago

1.1.2

9 months ago

0.45.0

12 months ago

0.44.0

1 year ago

0.44.1

1 year ago

0.43.0

1 year ago

0.41.0

1 year ago

0.42.0

1 year ago

0.40.2

1 year ago

0.38.2

2 years ago

0.38.9

2 years ago

0.38.8

2 years ago

0.38.7

2 years ago

0.38.6

2 years ago

0.38.5

2 years ago

0.38.4

2 years ago

0.38.3

2 years ago

0.40.0

2 years ago

0.40.1

2 years ago

0.39.0

2 years ago

0.38.10

2 years ago

0.38.1

2 years ago

0.38.0

2 years ago

0.37.0

2 years ago

0.36.0

2 years ago

0.35.0

2 years ago

0.34.3

2 years ago

0.34.2

2 years ago

0.34.1

2 years ago

0.34.0

2 years ago

0.33.3

2 years ago

0.33.2

2 years ago

0.33.1

2 years ago

0.20.1

2 years ago

0.20.0

2 years ago

0.19.0

2 years ago

0.32.1

2 years ago

0.15.0

2 years ago

0.17.0

2 years ago

0.32.0

2 years ago

0.30.1

2 years ago

0.30.0

2 years ago

0.29.0

2 years ago

0.27.0

2 years ago

0.25.1

2 years ago

0.25.0

2 years ago

0.23.0

2 years ago

0.21.1

2 years ago

0.21.0

2 years ago

0.16.3

2 years ago

0.16.4

2 years ago

0.16.5

2 years ago

0.16.6

2 years ago

0.16.7

2 years ago

0.33.0

2 years ago

0.14.0

2 years ago

0.16.1

2 years ago

0.18.0

2 years ago

0.16.2

2 years ago

0.31.0

2 years ago

0.28.0

2 years ago

0.26.2

2 years ago

0.26.1

2 years ago

0.26.0

2 years ago

0.24.1

2 years ago

0.24.0

2 years ago

0.22.0

2 years ago

0.8.5

2 years ago

0.8.4

2 years ago

0.10.0

2 years ago

0.11.0

2 years ago

0.9.0

2 years ago

0.8.1

2 years ago

0.12.0

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.13.0

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.7.0

2 years ago

0.5.0

2 years ago

0.6.0

2 years ago

0.4.0

2 years ago

0.1.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.3.1

2 years ago

0.0.3

2 years ago

0.0.1

2 years ago