@maplibre/maplibre-gl-style-spec
Advanced tools
Comparing version 20.3.0 to 20.3.1
{ | ||
"name": "@maplibre/maplibre-gl-style-spec", | ||
"description": "a specification for maplibre styles", | ||
"version": "20.3.0", | ||
"version": "20.3.1", | ||
"author": "MapLibre", | ||
@@ -25,3 +25,3 @@ "keywords": [ | ||
"mkdocs": "docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material", | ||
"mkdocs-build": "npm run generate-docs && docker run --rm -v ${PWD}:/docs squidfunk/mkdocs-material build", | ||
"mkdocs-build": "npm run generate-docs && docker run --rm -v ${PWD}:/docs squidfunk/mkdocs-material build --strict", | ||
"test-build": "jest --selectProjects=build", | ||
@@ -59,10 +59,10 @@ "test-integration": "jest --selectProjects=integration", | ||
"sort-object": "^3.0.3", | ||
"tinyqueue": "^2.0.3" | ||
"tinyqueue": "^3.0.0" | ||
}, | ||
"sideEffects": false, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^25.0.8", | ||
"@rollup/plugin-commonjs": "^26.0.1", | ||
"@rollup/plugin-json": "^6.1.0", | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@rollup/plugin-replace": "^5.0.5", | ||
"@rollup/plugin-replace": "^5.0.7", | ||
"@rollup/plugin-strip": "^3.0.4", | ||
@@ -74,5 +74,5 @@ "@rollup/plugin-terser": "^0.4.4", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.12.12", | ||
"@typescript-eslint/eslint-plugin": "^7.10.0", | ||
"@typescript-eslint/parser": "^7.10.0", | ||
"@types/node": "^22.1.0", | ||
"@typescript-eslint/eslint-plugin": "^7.17.0", | ||
"@typescript-eslint/parser": "^7.18.0", | ||
"dts-bundle-generator": "^9.5.1", | ||
@@ -83,17 +83,17 @@ "eslint": "^8.57.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-jest": "^28.5.0", | ||
"eslint-plugin-jsdoc": "^48.2.6", | ||
"eslint-plugin-react": "^7.34.1", | ||
"glob": "^10.4.1", | ||
"eslint-plugin-jest": "^28.8.0", | ||
"eslint-plugin-jsdoc": "^50.0.1", | ||
"eslint-plugin-react": "^7.35.0", | ||
"glob": "^11.0.0", | ||
"jest": "^29.7.0", | ||
"jest-canvas-mock": "^2.5.2", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"rollup": "^4.18.0", | ||
"rollup": "^4.20.0", | ||
"rollup-plugin-preserve-shebang": "^1.0.1", | ||
"semver": "^7.5.4", | ||
"ts-jest": "^29.1.3", | ||
"semver": "^7.6.3", | ||
"ts-jest": "^29.2.4", | ||
"ts-node": "^10.9.2", | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.4.5" | ||
"tslib": "^2.6.3", | ||
"typescript": "^5.5.4" | ||
} | ||
} |
@@ -63,12 +63,20 @@ import { | ||
if (!isValidNativeType(haystack, ['string', 'array'])) { | ||
throw new RuntimeError(`Expected second argument to be of type array or string, but found ${toString(typeOf(haystack))} instead.`); | ||
let fromIndex; | ||
if (this.fromIndex) { | ||
fromIndex = (this.fromIndex.evaluate(ctx) as number); | ||
} | ||
if (this.fromIndex) { | ||
const fromIndex = (this.fromIndex.evaluate(ctx) as number); | ||
if (isValidNativeType(haystack, ['string'])) { | ||
const rawIndex = haystack.indexOf(needle, fromIndex); | ||
if (rawIndex === -1) { | ||
return -1; | ||
} else { | ||
// The index may be affected by surrogate pairs, so get the length of the preceding substring. | ||
return [...haystack.slice(0, rawIndex)].length; | ||
} | ||
} else if (isValidNativeType(haystack, ['array'])) { | ||
return haystack.indexOf(needle, fromIndex); | ||
} else { | ||
throw new RuntimeError(`Expected second argument to be of type array or string, but found ${toString(typeOf(haystack))} instead.`); | ||
} | ||
return haystack.indexOf(needle); | ||
} | ||
@@ -75,0 +83,0 @@ |
@@ -36,3 +36,4 @@ import {NumberType, toString} from '../types'; | ||
if (typeof input === 'string') { | ||
return input.length; | ||
// The length may be affected by surrogate pairs. | ||
return [...input].length; | ||
} else if (Array.isArray(input)) { | ||
@@ -39,0 +40,0 @@ return input.length; |
@@ -59,12 +59,15 @@ import { | ||
if (!isValidNativeType(input, ['string', 'array'])) { | ||
throw new RuntimeError(`Expected first argument to be of type array or string, but found ${toString(typeOf(input))} instead.`); | ||
let endIndex; | ||
if (this.endIndex) { | ||
endIndex = (this.endIndex.evaluate(ctx) as number); | ||
} | ||
if (this.endIndex) { | ||
const endIndex = (this.endIndex.evaluate(ctx) as number); | ||
if (isValidNativeType(input, ['string'])) { | ||
// Indices may be affected by surrogate pairs. | ||
return [...input].slice(beginIndex, endIndex).join(''); | ||
} else if (isValidNativeType(input, ['array'])) { | ||
return input.slice(beginIndex, endIndex); | ||
} else { | ||
throw new RuntimeError(`Expected first argument to be of type array or string, but found ${toString(typeOf(input))} instead.`); | ||
} | ||
return input.slice(beginIndex); | ||
} | ||
@@ -71,0 +74,0 @@ |
@@ -391,1 +391,242 @@ import {createPropertyExpression, Feature, GlobalProperties, StylePropertyExpression} from '../expression'; | ||
}); | ||
describe('index-of expression', () => { | ||
test('requires a needle', () => { | ||
const response = createExpression(['index-of']); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('requires a haystack', () => { | ||
const response = createExpression(['index-of', 'a']); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('rejects a fourth argument', () => { | ||
const response = createExpression(['index-of', 'a', 'abc', 1, 8]); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('requires a primitive as the needle', () => { | ||
const response = createExpression(['index-of', ['literal', ['a']], ['a', 'b', 'c']]); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('requires a string or array as the haystack', () => { | ||
const response = createExpression(['index-of', 't', true]); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('finds an empty substring in an empty string', () => { | ||
const response = createExpression(['index-of', '', '']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(0); | ||
}); | ||
test('finds an empty substring in a non-empty string', () => { | ||
const response = createExpression(['index-of', '', 'abc']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(0); | ||
}); | ||
test('cannot find a non-empty substring in an empty string', () => { | ||
const response = createExpression(['index-of', 'abc', '']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(-1); | ||
}); | ||
test('finds a non-empty substring in a non-empty string', () => { | ||
const response = createExpression(['index-of', 'b', 'abc']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(1); | ||
}); | ||
test('only finds the first occurrence in a string', () => { | ||
const response = createExpression(['index-of', 'b', 'abbc']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(1); | ||
}); | ||
test('starts looking for the substring at a positive start index', () => { | ||
const response = createExpression(['index-of', 'a', 'abc', 1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(-1); | ||
}); | ||
test('starts looking for the substring at a negative start index', () => { | ||
const response = createExpression(['index-of', 'c', 'abc', -1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(2); | ||
}); | ||
test('counts a non-ASCII character as a single character', () => { | ||
const response = createExpression(['index-of', '镇', '市镇']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(1); | ||
}); | ||
test('counts a surrogate pair as a single character', () => { | ||
const response = createExpression(['index-of', '市镇', '丐𦨭市镇']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(2); | ||
}); | ||
test('cannot find an element in an empty array', () => { | ||
const response = createExpression(['index-of', 1, ['literal', []]]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(-1); | ||
}); | ||
test('finds an element in a non-empty array', () => { | ||
const response = createExpression(['index-of', 2, ['literal', [1, 2, 3]]]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(1); | ||
}); | ||
test('only finds the first occurrence in an array', () => { | ||
const response = createExpression(['index-of', 2, ['literal', [1, 2, 2, 3]]]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(1); | ||
}); | ||
test('starts looking for the element at a positive start index', () => { | ||
const response = createExpression(['index-of', 1, ['literal', [1, 2, 3]], 1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(-1); | ||
}); | ||
test('starts looking for the element at a negative start index', () => { | ||
const response = createExpression(['index-of', 3, ['literal', [1, 2, 3]], -1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(2); | ||
}); | ||
}); | ||
describe('length expression', () => { | ||
test('requires an argument', () => { | ||
const response = createExpression(['length']); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('requires a string or array as the argument', () => { | ||
const response = createExpression(['length', true]); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('rejects a second argument', () => { | ||
const response = createExpression(['length', 'abc', 'def']); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('measures an empty string', () => { | ||
const response = createExpression(['length', '']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(0); | ||
}); | ||
test('measures a non-empty string', () => { | ||
const response = createExpression(['length', 'abc']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(3); | ||
}); | ||
test('counts a non-ASCII character as a single character', () => { | ||
const response = createExpression(['length', '市镇']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(2); | ||
}); | ||
test('counts a surrogate pair as a single character', () => { | ||
const response = createExpression(['length', '丐𦨭市镇']); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(4); | ||
}); | ||
test('measures an empty array', () => { | ||
const response = createExpression(['length', ['literal', []]]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(0); | ||
}); | ||
test('measures a non-empty array', () => { | ||
const response = createExpression(['length', ['literal', [1, 2, 3]]]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(3); | ||
}); | ||
}); | ||
describe('slice expression', () => { | ||
test('requires an input argument', () => { | ||
const response = createExpression(['slice']); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('requires a start index argument', () => { | ||
const response = createExpression(['slice', 'abc']); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('rejects a fourth argument', () => { | ||
const response = createExpression(['slice', 'abc', 0, 1, 8]); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('requires a string or array as the input argument', () => { | ||
const response = createExpression(['slice', true, 0]); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('requires a number as the start index argument', () => { | ||
const response = createExpression(['slice', 'abc', true]); | ||
expect(response.result).toBe('error'); | ||
}); | ||
test('slices an empty string', () => { | ||
const response = createExpression(['slice', '', 0]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(''); | ||
}); | ||
test('slices a string starting at the beginning', () => { | ||
const response = createExpression(['slice', 'abc', 0]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe('abc'); | ||
}); | ||
test('slices a string starting at the middle', () => { | ||
const response = createExpression(['slice', 'abc', 1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe('bc'); | ||
}); | ||
test('slices a string starting at the end', () => { | ||
const response = createExpression(['slice', 'abc', 3]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(''); | ||
}); | ||
test('slices a string backwards from the end', () => { | ||
const response = createExpression(['slice', 'abc', -2]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe('bc'); | ||
}); | ||
test('slices a string by a zero-length range', () => { | ||
const response = createExpression(['slice', 'abc', 1, 1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(''); | ||
}); | ||
test('slices a string by a negative-length range', () => { | ||
const response = createExpression(['slice', 'abc', 2, 1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe(''); | ||
}); | ||
test('avoids splitting a non-ASCII character', () => { | ||
const response = createExpression(['slice', '市镇', 1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe('镇'); | ||
}); | ||
test('avoids splitting a surrogate pair', () => { | ||
const response = createExpression(['slice', '丐𦨭市镇', 2]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toBe('市镇'); | ||
}); | ||
test('slices an empty array', () => { | ||
const response = createExpression(['slice', ['literal', []], 0]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toEqual([]); | ||
}); | ||
test('slices an array starting at the beginning', () => { | ||
const response = createExpression(['slice', ['literal', [1, 2, 3]], 0]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toEqual([1, 2, 3]); | ||
}); | ||
test('slices an array starting at the middle', () => { | ||
const response = createExpression(['slice', ['literal', [1, 2, 3]], 1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toEqual([2, 3]); | ||
}); | ||
test('slices an array starting at the end', () => { | ||
const response = createExpression(['slice', ['literal', [1, 2, 3]], 3]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toEqual([]); | ||
}); | ||
test('slices an array backwards from the end', () => { | ||
const response = createExpression(['slice', ['literal', [1, 2, 3]], -2]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toEqual([2, 3]); | ||
}); | ||
test('slices an array by a zero-length range', () => { | ||
const response = createExpression(['slice', ['literal', [1, 2, 3]], 1, 1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toEqual([]); | ||
}); | ||
test('slices an array by a negative-length range', () => { | ||
const response = createExpression(['slice', ['literal', [1, 2, 3]], 2, 1]); | ||
expect(response.result).toBe('success'); | ||
expect((response.value as StyleExpression)?.evaluate({zoom: 20})).toEqual([]); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
9096917
96073
+ Addedtinyqueue@3.0.0(transitive)
- Removedtinyqueue@2.0.3(transitive)
Updatedtinyqueue@^3.0.0