Skip to content

Commit 7626b7c

Browse files
authored
Jordan/optimize utils (#231)
* Add license headers, add sprintf to utils * Bump logging/utils to 0.1.2 and use internal sprintf function
1 parent 78ba995 commit 7626b7c

File tree

12 files changed

+198
-93
lines changed

12 files changed

+198
-93
lines changed

packages/logging/package-lock.json

Lines changed: 1 addition & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/logging/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@optimizely/js-sdk-logging",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Optimizely Full Stack Core Logging",
55
"author": "jordangarcia <[email protected]>",
66
"homepage": "https://github.com/optimizely/javascript-sdk",
@@ -20,12 +20,10 @@
2020
"prepublishOnly": "jest && npm run tsc"
2121
},
2222
"dependencies": {
23-
"@optimizely/js-sdk-utils": "^0.1.1",
24-
"sprintf-js": "^1.1.1"
23+
"@optimizely/js-sdk-utils": "^0.1.2"
2524
},
2625
"devDependencies": {
2726
"@types/jest": "^23.3.12",
28-
"@types/sprintf-js": "^1.1.1",
2927
"jest": "^23.6.0",
3028
"ts-jest": "^23.10.5"
3129
}

packages/logging/src/errorHandler.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2019, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
/**
217
* @export
318
* @interface ErrorHandler

packages/logging/src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2019, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
export * from './errorHandler'
217
export * from './models'
318
export * from './logger'

packages/logging/src/logger.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
import { sprintf } from 'sprintf-js'
1+
/**
2+
* Copyright 2019, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
216
import { getErrorHandler } from './errorHandler'
3-
import { isValidEnum } from '@optimizely/js-sdk-utils'
17+
import { isValidEnum, sprintf } from '@optimizely/js-sdk-utils'
418

519
import { LogLevel, LoggerFacade, LogManager, LogHandler } from './models'
620

packages/logging/src/models.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* Copyright 2019, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
export enum LogLevel {
217
NOTSET = 0,
318
DEBUG = 1,

packages/optimizely-sdk/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/utils/__tests__/utils.spec.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference types="jest" />
2-
import { isValidEnum, groupBy, objectValues, find, keyBy } from '../src/utils'
2+
import { isValidEnum, groupBy, objectValues, find, keyBy, sprintf } from '../src'
33

44
describe('utils', () => {
55
describe('isValidEnum', () => {
@@ -84,4 +84,34 @@ describe('utils', () => {
8484
})
8585
})
8686
})
87+
88+
describe('sprintf', () => {
89+
it('sprintf(msg)', () => {
90+
expect(sprintf('this is my message')).toBe('this is my message')
91+
})
92+
93+
it('sprintf(msg, arg1)', () => {
94+
expect(sprintf('hi %s', 'jordan')).toBe('hi jordan')
95+
})
96+
97+
it('sprintf(msg, arg1, arg2)', () => {
98+
expect(sprintf('hi %s its %s', 'jordan', 'jon')).toBe('hi jordan its jon')
99+
})
100+
101+
it('should print undefined if an argument is missing', () => {
102+
expect(sprintf('hi %s its %s', 'jordan')).toBe('hi jordan its undefined')
103+
})
104+
105+
it('should evaluate a function', () => {
106+
expect(sprintf('hi %s its %s', 'jordan', () => 'a function')).toBe('hi jordan its a function')
107+
})
108+
109+
it('should work with numbers', () => {
110+
expect(sprintf('hi %s', 123)).toBe('hi 123')
111+
})
112+
113+
it('should not error when passed an object', () => {
114+
expect(sprintf('hi %s', { foo: 'bar' })).toBe('hi [object Object]')
115+
})
116+
})
87117
})

packages/utils/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@optimizely/js-sdk-utils",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Optimizely Full Stack Utils",
55
"author": "jordangarcia <[email protected]>",
66
"homepage": "https://github.com/optimizely/javascript-sdk",

0 commit comments

Comments
 (0)