@promoboxx/use-filter 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/lib/buildDefaultFilterInfo.js +35 -0
- package/dist/lib/getOffsetFromPage.js +6 -0
- package/dist/lib/getPageFromOffset.js +6 -0
- package/dist/lib/shallowEqual.js +23 -0
- package/dist/lib/shallowEqual.test.js +54 -0
- package/dist/store/index.js +15 -0
- package/dist/store/memoryStore.js +15 -0
- package/dist/useFilter.js +184 -0
- package/dist/useFilter.test.js +581 -0
- package/package.json +14 -3
- package/.eslintrc.js +0 -19
- package/.github/workflows/main.yml +0 -32
- package/.vscode/settings.json +0 -3
- package/Makefile +0 -31
- package/jest.config.js +0 -196
- package/prettier.config.js +0 -1
- package/src/lib/buildDefaultFilterInfo.ts +0 -35
- package/src/lib/getOffsetFromPage.ts +0 -5
- package/src/lib/getPageFromOffset.ts +0 -5
- package/src/lib/shallowEqual.test.ts +0 -71
- package/src/lib/shallowEqual.ts +0 -26
- package/src/store/index.ts +0 -21
- package/src/store/memoryStore.ts +0 -19
- package/src/useFilter.test.tsx +0 -449
- package/src/useFilter.ts +0 -280
- package/tsconfig.json +0 -75
package/Makefile
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
all: test
|
|
2
|
-
|
|
3
|
-
prepare-env:
|
|
4
|
-
ifeq ($(CI),true)
|
|
5
|
-
npm ci --ignore-scripts
|
|
6
|
-
else
|
|
7
|
-
npm install
|
|
8
|
-
endif
|
|
9
|
-
|
|
10
|
-
prepare-when-local:
|
|
11
|
-
ifneq ($(CI),true)
|
|
12
|
-
$(MAKE) prepare-env
|
|
13
|
-
endif
|
|
14
|
-
|
|
15
|
-
build: prepare-when-local
|
|
16
|
-
rm -rf dist/
|
|
17
|
-
npx tsc
|
|
18
|
-
|
|
19
|
-
test: prepare-when-local
|
|
20
|
-
ifeq ($(CI),true)
|
|
21
|
-
npx jest --ci
|
|
22
|
-
else
|
|
23
|
-
npx jest --watch
|
|
24
|
-
endif
|
|
25
|
-
|
|
26
|
-
deploy:
|
|
27
|
-
ifeq ($(GITHUB_REF),refs/heads/main)
|
|
28
|
-
npx standard-version
|
|
29
|
-
git push origin --tags HEAD
|
|
30
|
-
npm publish
|
|
31
|
-
endif
|
package/jest.config.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* For a detailed explanation regarding each configuration property and type check, visit:
|
|
3
|
-
* https://jestjs.io/docs/configuration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const config = {
|
|
7
|
-
// All imported modules in your tests should be mocked automatically
|
|
8
|
-
// automock: false,
|
|
9
|
-
|
|
10
|
-
// Stop running tests after `n` failures
|
|
11
|
-
// bail: 0,
|
|
12
|
-
|
|
13
|
-
// The directory where Jest should store its cached dependency information
|
|
14
|
-
// cacheDirectory: "/tmp/jest_rs",
|
|
15
|
-
|
|
16
|
-
// Automatically clear mock calls and instances between every test
|
|
17
|
-
clearMocks: true,
|
|
18
|
-
|
|
19
|
-
// Indicates whether the coverage information should be collected while executing the test
|
|
20
|
-
// collectCoverage: false,
|
|
21
|
-
|
|
22
|
-
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
23
|
-
// collectCoverageFrom: undefined,
|
|
24
|
-
|
|
25
|
-
// The directory where Jest should output its coverage files
|
|
26
|
-
// coverageDirectory: undefined,
|
|
27
|
-
|
|
28
|
-
// An array of regexp pattern strings used to skip coverage collection
|
|
29
|
-
// coveragePathIgnorePatterns: [
|
|
30
|
-
// "/node_modules/"
|
|
31
|
-
// ],
|
|
32
|
-
|
|
33
|
-
// Indicates which provider should be used to instrument code for coverage
|
|
34
|
-
coverageProvider: 'v8',
|
|
35
|
-
|
|
36
|
-
// A list of reporter names that Jest uses when writing coverage reports
|
|
37
|
-
// coverageReporters: [
|
|
38
|
-
// "json",
|
|
39
|
-
// "text",
|
|
40
|
-
// "lcov",
|
|
41
|
-
// "clover"
|
|
42
|
-
// ],
|
|
43
|
-
|
|
44
|
-
// An object that configures minimum threshold enforcement for coverage results
|
|
45
|
-
// coverageThreshold: undefined,
|
|
46
|
-
|
|
47
|
-
// A path to a custom dependency extractor
|
|
48
|
-
// dependencyExtractor: undefined,
|
|
49
|
-
|
|
50
|
-
// Make calling deprecated APIs throw helpful error messages
|
|
51
|
-
// errorOnDeprecated: false,
|
|
52
|
-
|
|
53
|
-
// Force coverage collection from ignored files using an array of glob patterns
|
|
54
|
-
// forceCoverageMatch: [],
|
|
55
|
-
|
|
56
|
-
// A path to a module which exports an async function that is triggered once before all test suites
|
|
57
|
-
// globalSetup: undefined,
|
|
58
|
-
|
|
59
|
-
// A path to a module which exports an async function that is triggered once after all test suites
|
|
60
|
-
// globalTeardown: undefined,
|
|
61
|
-
|
|
62
|
-
// A set of global variables that need to be available in all test environments
|
|
63
|
-
// globals: {},
|
|
64
|
-
|
|
65
|
-
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
66
|
-
// maxWorkers: "50%",
|
|
67
|
-
|
|
68
|
-
// An array of directory names to be searched recursively up from the requiring module's location
|
|
69
|
-
// moduleDirectories: [
|
|
70
|
-
// "node_modules"
|
|
71
|
-
// ],
|
|
72
|
-
|
|
73
|
-
// An array of file extensions your modules use
|
|
74
|
-
// moduleFileExtensions: [
|
|
75
|
-
// "js",
|
|
76
|
-
// "jsx",
|
|
77
|
-
// "ts",
|
|
78
|
-
// "tsx",
|
|
79
|
-
// "json",
|
|
80
|
-
// "node"
|
|
81
|
-
// ],
|
|
82
|
-
|
|
83
|
-
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
84
|
-
// moduleNameMapper: {},
|
|
85
|
-
|
|
86
|
-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
87
|
-
// modulePathIgnorePatterns: [],
|
|
88
|
-
|
|
89
|
-
// Activates notifications for test results
|
|
90
|
-
// notify: false,
|
|
91
|
-
|
|
92
|
-
// An enum that specifies notification mode. Requires { notify: true }
|
|
93
|
-
// notifyMode: "failure-change",
|
|
94
|
-
|
|
95
|
-
// A preset that is used as a base for Jest's configuration
|
|
96
|
-
preset: 'ts-jest/presets/js-with-ts',
|
|
97
|
-
|
|
98
|
-
// Run tests from one or more projects
|
|
99
|
-
// projects: undefined,
|
|
100
|
-
|
|
101
|
-
// Use this configuration option to add custom reporters to Jest
|
|
102
|
-
// reporters: undefined,
|
|
103
|
-
|
|
104
|
-
// Automatically reset mock state between every test
|
|
105
|
-
// resetMocks: false,
|
|
106
|
-
|
|
107
|
-
// Reset the module registry before running each individual test
|
|
108
|
-
// resetModules: false,
|
|
109
|
-
|
|
110
|
-
// A path to a custom resolver
|
|
111
|
-
// resolver: undefined,
|
|
112
|
-
|
|
113
|
-
// Automatically restore mock state between every test
|
|
114
|
-
// restoreMocks: false,
|
|
115
|
-
|
|
116
|
-
// The root directory that Jest should scan for tests and modules within
|
|
117
|
-
// rootDir: undefined,
|
|
118
|
-
|
|
119
|
-
// A list of paths to directories that Jest should use to search for files in
|
|
120
|
-
// roots: [
|
|
121
|
-
// "<rootDir>"
|
|
122
|
-
// ],
|
|
123
|
-
|
|
124
|
-
// Allows you to use a custom runner instead of Jest's default test runner
|
|
125
|
-
// runner: "jest-runner",
|
|
126
|
-
|
|
127
|
-
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
128
|
-
// setupFiles: [],
|
|
129
|
-
|
|
130
|
-
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
131
|
-
// setupFilesAfterEnv: [],
|
|
132
|
-
|
|
133
|
-
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
134
|
-
// slowTestThreshold: 5,
|
|
135
|
-
|
|
136
|
-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
137
|
-
// snapshotSerializers: [],
|
|
138
|
-
|
|
139
|
-
// The test environment that will be used for testing
|
|
140
|
-
testEnvironment: 'jsdom',
|
|
141
|
-
|
|
142
|
-
// Options that will be passed to the testEnvironment
|
|
143
|
-
// testEnvironmentOptions: {},
|
|
144
|
-
|
|
145
|
-
// Adds a location field to test results
|
|
146
|
-
// testLocationInResults: false,
|
|
147
|
-
|
|
148
|
-
// The glob patterns Jest uses to detect test files
|
|
149
|
-
// testMatch: [
|
|
150
|
-
// "**/__tests__/**/*.[jt]s?(x)",
|
|
151
|
-
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
152
|
-
// ],
|
|
153
|
-
|
|
154
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
155
|
-
// testPathIgnorePatterns: [
|
|
156
|
-
// "/node_modules/"
|
|
157
|
-
// ],
|
|
158
|
-
|
|
159
|
-
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
160
|
-
// testRegex: [],
|
|
161
|
-
|
|
162
|
-
// This option allows the use of a custom results processor
|
|
163
|
-
// testResultsProcessor: undefined,
|
|
164
|
-
|
|
165
|
-
// This option allows use of a custom test runner
|
|
166
|
-
// testRunner: "jest-circus/runner",
|
|
167
|
-
|
|
168
|
-
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
|
|
169
|
-
// testURL: "http://localhost",
|
|
170
|
-
|
|
171
|
-
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
|
|
172
|
-
// timers: "real",
|
|
173
|
-
|
|
174
|
-
// A map from regular expressions to paths to transformers
|
|
175
|
-
// transform: undefined,
|
|
176
|
-
|
|
177
|
-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
178
|
-
// transformIgnorePatterns: [
|
|
179
|
-
// "/node_modules/",
|
|
180
|
-
// "\\.pnp\\.[^\\/]+$"
|
|
181
|
-
// ],
|
|
182
|
-
|
|
183
|
-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
184
|
-
// unmockedModulePathPatterns: undefined,
|
|
185
|
-
|
|
186
|
-
// Indicates whether each individual test should be reported during the run
|
|
187
|
-
verbose: true,
|
|
188
|
-
|
|
189
|
-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
190
|
-
// watchPathIgnorePatterns: [],
|
|
191
|
-
|
|
192
|
-
// Whether to use watchman for file crawling
|
|
193
|
-
// watchman: true,
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
module.exports = config
|
package/prettier.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('@promoboxx/eslint-config/prettier.config')
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { FilterInfo } from '../useFilter'
|
|
2
|
-
|
|
3
|
-
import getOffsetFromPage from './getOffsetFromPage'
|
|
4
|
-
import getPageFromOffset from './getPageFromOffset'
|
|
5
|
-
|
|
6
|
-
function buildDefaultFilterInfo<T>(
|
|
7
|
-
filterInfo: Partial<FilterInfo<T>> = {},
|
|
8
|
-
): FilterInfo<T> {
|
|
9
|
-
const merged: FilterInfo<T> = {
|
|
10
|
-
// Cast here to work around "'T' could be instantiated with an arbitrary
|
|
11
|
-
// type which could be unrelated to '{}'"
|
|
12
|
-
filter: {} as T,
|
|
13
|
-
|
|
14
|
-
sort: undefined,
|
|
15
|
-
pageSize: 20,
|
|
16
|
-
lastRefreshAt: new Date().getTime(),
|
|
17
|
-
totalResults: 1,
|
|
18
|
-
totalPages: 1,
|
|
19
|
-
offset: 0,
|
|
20
|
-
page: 1,
|
|
21
|
-
...filterInfo,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// If there's a page but no offset, set the offset.
|
|
25
|
-
if (filterInfo.page != null && filterInfo.offset == null) {
|
|
26
|
-
merged.offset = getOffsetFromPage(filterInfo.page, merged.pageSize)
|
|
27
|
-
// If there's an offset but no page, set the page.
|
|
28
|
-
} else if (filterInfo.page == null && filterInfo.offset != null) {
|
|
29
|
-
merged.page = getPageFromOffset(filterInfo.offset, merged.pageSize)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return merged
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export default buildDefaultFilterInfo
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import shallowEqual from './shallowEqual'
|
|
2
|
-
|
|
3
|
-
describe('shallowEqual', () => {
|
|
4
|
-
it('should return true if arguments fields are equal', () => {
|
|
5
|
-
expect(
|
|
6
|
-
shallowEqual({ a: 1, b: 2, c: undefined }, { a: 1, b: 2, c: undefined }),
|
|
7
|
-
).toBe(true)
|
|
8
|
-
|
|
9
|
-
expect(shallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe(true)
|
|
10
|
-
|
|
11
|
-
const o = {}
|
|
12
|
-
expect(shallowEqual({ a: 1, b: 2, c: o }, { a: 1, b: 2, c: o })).toBe(true)
|
|
13
|
-
|
|
14
|
-
const d = function () {
|
|
15
|
-
return 1
|
|
16
|
-
}
|
|
17
|
-
expect(shallowEqual({ a: 1, b: 2, c: o, d }, { a: 1, b: 2, c: o, d })).toBe(
|
|
18
|
-
true,
|
|
19
|
-
)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should return false if arguments fields are different function identities', () => {
|
|
23
|
-
expect(
|
|
24
|
-
shallowEqual(
|
|
25
|
-
{
|
|
26
|
-
a: 1,
|
|
27
|
-
b: 2,
|
|
28
|
-
d() {
|
|
29
|
-
return 1
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
a: 1,
|
|
34
|
-
b: 2,
|
|
35
|
-
d() {
|
|
36
|
-
return 1
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
),
|
|
40
|
-
).toBe(false)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('should return false if first argument has too many keys', () => {
|
|
44
|
-
expect(shallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 })).toBe(false)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('should return false if second argument has too many keys', () => {
|
|
48
|
-
expect(shallowEqual({ a: 1, b: 2 }, { a: 1, b: 2, c: 3 })).toBe(false)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('should return false if arguments have different keys', () => {
|
|
52
|
-
expect(
|
|
53
|
-
shallowEqual({ a: 1, b: 2, c: undefined }, { a: 1, bb: 2, c: undefined }),
|
|
54
|
-
).toBe(false)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('should compare two NaN values', () => {
|
|
58
|
-
expect(shallowEqual(NaN, NaN)).toBe(true)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('should compare empty objects, with false', () => {
|
|
62
|
-
expect(shallowEqual({}, false)).toBe(false)
|
|
63
|
-
expect(shallowEqual(false, {})).toBe(false)
|
|
64
|
-
expect(shallowEqual([], false)).toBe(false)
|
|
65
|
-
expect(shallowEqual(false, [])).toBe(false)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('should compare two zero values', () => {
|
|
69
|
-
expect(shallowEqual(0, 0)).toBe(true)
|
|
70
|
-
})
|
|
71
|
-
})
|
package/src/lib/shallowEqual.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const shallowEqual = (objA: any, objB: any) => {
|
|
2
|
-
if (Object.is(objA, objB)) {
|
|
3
|
-
return true
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
if (typeof objA !== 'object' || !objA || typeof objB !== 'object' || !objB) {
|
|
7
|
-
return false
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const keysA = Object.keys(objA)
|
|
11
|
-
const keysB = Object.keys(objB)
|
|
12
|
-
|
|
13
|
-
if (keysA.length !== keysB.length) {
|
|
14
|
-
return false
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
for (const key of keysA) {
|
|
18
|
-
if (!Object.is(objA[key], objB[key])) {
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return true
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default shallowEqual
|
package/src/store/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { FilterInfo } from '../useFilter'
|
|
2
|
-
|
|
3
|
-
export interface FilterStore {
|
|
4
|
-
getFilter(namespace: string): FilterInfo<any> | null | undefined
|
|
5
|
-
saveFilter(namespace: string, filter: FilterInfo<any>): void
|
|
6
|
-
clear(): void
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
let store: FilterStore | undefined
|
|
10
|
-
|
|
11
|
-
export function setFilterStore(newStore: FilterStore) {
|
|
12
|
-
store = newStore
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function getFilterStore() {
|
|
16
|
-
if (!store) {
|
|
17
|
-
throw new Error('A store must be set with setFilterStore')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return store
|
|
21
|
-
}
|
package/src/store/memoryStore.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { FilterInfo } from '../useFilter'
|
|
2
|
-
|
|
3
|
-
import { FilterStore } from '.'
|
|
4
|
-
|
|
5
|
-
let filters: Record<string, FilterInfo<any>> = {}
|
|
6
|
-
|
|
7
|
-
const memoryStore: FilterStore = {
|
|
8
|
-
getFilter(namespace) {
|
|
9
|
-
return filters[namespace]
|
|
10
|
-
},
|
|
11
|
-
saveFilter(namespace, filter) {
|
|
12
|
-
filters[namespace] = filter
|
|
13
|
-
},
|
|
14
|
-
clear() {
|
|
15
|
-
filters = {}
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default memoryStore
|