-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add node sample for cloud composer tutorial #1708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sofisl
merged 13 commits into
GoogleCloudPlatform:master
from
sofisl:addComposerTutorialSample
Apr 16, 2020
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2b7aadc
feat: add node sample for cloud compser tutorial
sofisl 8aeb93d
Merge branch 'master' into addComposerTutorialSample
sofisl 9d8a968
fix: respond to Leah comments
sofisl 00c3abb
Merge branch 'addComposerTutorialSample' of github.com:sofisl/nodejs-…
sofisl 8e0bd93
feat: add README
sofisl e5380f3
fix: readme
sofisl 89c3d49
Merge branch 'master' into addComposerTutorialSample
sofisl fceb9a9
fix: change readme and codeowners file
sofisl c3800ee
Merge branch 'addComposerTutorialSample' of github.com:sofisl/nodejs-…
sofisl ccf629c
Merge branch 'master' into addComposerTutorialSample
sofisl ad7ac34
fix: add owners in alphabetical order
sofisl e1388a0
Merge branch 'addComposerTutorialSample' of github.com:sofisl/nodejs-…
sofisl 80c7718
Merge branch 'master' into addComposerTutorialSample
sofisl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* eslint-disable func-style */ | ||
| // Copyright 2020 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| module.exports = function main( | ||
| line = 'tampa, 106, january, null, null, 08--17-2019' | ||
| ) { | ||
| // [START transform_CSV_to_JSON] | ||
|
|
||
| function transformCSVtoJSON(line) { | ||
| const values = line.split(','); | ||
| const properties = [ | ||
| 'location', | ||
| 'average_temperature', | ||
| 'month', | ||
| 'inches_of_rain', | ||
| 'is_current', | ||
| 'latest_measurement', | ||
| ]; | ||
| const weatherInCity = {}; | ||
|
|
||
| for (let count = 0; count < values.length; count++) { | ||
| if (values[count] !== 'null') { | ||
| weatherInCity[properties[count]] = values[count]; | ||
| } | ||
| } | ||
|
|
||
| const jsonString = JSON.stringify(weatherInCity); | ||
| return jsonString; | ||
| } | ||
|
|
||
| transformCSVtoJSON(line); | ||
| // [END transform_CSV_to_JSON] | ||
| return transformCSVtoJSON(line); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "nodejs-docs-samples-composer", | ||
| "description": "Node.js Google Composer sample.", | ||
| "version": "0.0.1", | ||
| "private": true, | ||
| "license": "Apache-2.0", | ||
| "author": "Google Inc.", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" | ||
| }, | ||
| "engines": { | ||
| "node": ">=8.0.0" | ||
| }, | ||
| "scripts": { | ||
| "test": "mocha --exit test/*.test.js" | ||
| }, | ||
| "devDependencies": { | ||
| "chai": "^4.2.0", | ||
| "mocha": "^7.0.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| const {assert} = require('chai'); | ||
| const tutorial = require('../composerJSTutorial.js'); | ||
|
|
||
| const lineTest = 'tampa, 106, january, null, null, 08-17-2019'; | ||
|
|
||
| it('should separate out a line and turn into a json string', () => { | ||
| const output = tutorial(lineTest); | ||
| console.log(output); | ||
sofisl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| assert.match( | ||
| output, | ||
| new RegExp( | ||
| '{"location":"tampa","average_temperature":" 106","month":" january","inches_of_rain":" null","is_current":" null","latest_measurement":" 08-17-2019"}' | ||
| ) | ||
| ); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.