-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit of code * Fleshing out tests * Removing passing 'result' recursively * Updating README.md, fixing UMD output * Adding '.github' directory
- Loading branch information
Showing
22 changed files
with
4,504 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
github: [avoidwork] |
This file contains 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,12 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: github-actions | ||
directory: "/" | ||
schedule: | ||
interval: weekly | ||
open-pull-requests-limit: 10 | ||
- package-ecosystem: npm | ||
directory: "/" | ||
schedule: | ||
interval: daily | ||
open-pull-requests-limit: 10 |
This file contains 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,47 @@ | ||
--- | ||
name: ci | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [18.x, 20.x] | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
|
||
- name: Setup Node ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
always-auth: false | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build | ||
run: npm run rollup | ||
|
||
- name: Run Tests | ||
run: npm run test | ||
|
||
automerge: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
contents: write | ||
steps: | ||
- uses: fastify/github-action-merge-dependabot@v3 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
This file contains 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
This file contains 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 @@ | ||
npm test |
This file contains 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 |
---|---|---|
@@ -1,2 +1,200 @@ | ||
# tiny-strings | ||
String scraper | ||
# Tiny Strings | ||
|
||
Scrape Strings from Arrays and Objects. | ||
|
||
## API | ||
|
||
### strings(*arg = {}, keys = false*) | ||
|
||
Returns an `Array` of `Strings` extracted from `arg` | ||
|
||
param {Array} or {Object} to scrape | ||
param {Boolean} to include Object keys | ||
return {Array} Array of Strings scraped from 'arg' | ||
|
||
**Example** | ||
|
||
Without keys | ||
|
||
```javascript | ||
strings({...}); | ||
``` | ||
|
||
With keys | ||
```javascript | ||
strings({...}, true); | ||
``` | ||
|
||
## Testing | ||
|
||
Tiny Strings has 100% code coverage with its tests. | ||
|
||
```console | ||
------------------|---------|----------|---------|---------|------------------- | ||
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ||
------------------|---------|----------|---------|---------|------------------- | ||
All files | 100 | 90.9 | 100 | 100 | | ||
tiny-strings.cjs | 100 | 90.9 | 100 | 100 | 14,25 | ||
------------------|---------|----------|---------|---------|------------------- | ||
``` | ||
|
||
## Example | ||
|
||
### Input | ||
|
||
```javascript | ||
import {strings} from "tiny-strings"; | ||
const extracted = strings([ | ||
{ | ||
"_id": "66897c0b5bb3f3bda598a7be", | ||
"index": 0, | ||
"guid": "57cc37b7-ea7b-4cf5-b07e-238a15cc1cdd", | ||
"isActive": true, | ||
"balance": "$1,290.80", | ||
"picture": "http://placehold.it/32x32", | ||
"age": 21, | ||
"eyeColor": "blue", | ||
"name": "Valeria Jenkins", | ||
"gender": "female", | ||
"company": "GEOLOGIX", | ||
"email": "[email protected]", | ||
"phone": "+1 (976) 597-3338", | ||
"address": "681 Jackson Place, Collins, Nevada, 8477", | ||
"about": "Officia sunt fugiat aute eiusmod cillum excepteur enim consectetur in pariatur consequat cupidatat. Id minim anim sint cupidatat nostrud labore esse proident eiusmod eu. Dolor sit aute adipisicing est proident eiusmod voluptate reprehenderit sunt aliquip non quis. Lorem voluptate laboris aliquip cupidatat.\r\n", | ||
"registered": "2016-04-05T01:14:10 +04:00", | ||
"latitude": 8.514373, | ||
"longitude": -22.578972, | ||
"tags": [ | ||
"voluptate", | ||
"esse", | ||
"amet", | ||
"mollit", | ||
"in", | ||
"consectetur", | ||
"sunt" | ||
], | ||
"friends": [ | ||
{ | ||
"id": 0, | ||
"name": "Moore Howell" | ||
}, | ||
{ | ||
"id": 1, | ||
"name": "Summer Cline" | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "Francis Simon" | ||
} | ||
], | ||
"greeting": "Hello, Valeria Jenkins! You have 1 unread messages.", | ||
"favoriteFruit": "banana" | ||
}, | ||
{ | ||
"_id": "66897c0b0eea9250887803d6", | ||
"index": 1, | ||
"guid": "6eac3134-b442-4289-a498-ef9b5624f196", | ||
"isActive": false, | ||
"balance": "$1,302.96", | ||
"picture": "http://placehold.it/32x32", | ||
"age": 28, | ||
"eyeColor": "brown", | ||
"name": "Amanda Rodgers", | ||
"gender": "female", | ||
"company": "GRAINSPOT", | ||
"email": "[email protected]", | ||
"phone": "+1 (987) 457-3247", | ||
"address": "650 Osborn Street, Edenburg, New Jersey, 1377", | ||
"about": "Eu minim enim aliquip nulla aliquip elit sit nostrud dolore reprehenderit aliquip sit qui Lorem. Enim et excepteur dolor velit minim nulla ullamco nisi. Qui adipisicing id occaecat nisi duis quis sint minim laborum minim id. Do id aliqua deserunt incididunt nulla officia nostrud reprehenderit laborum aliquip qui. Veniam pariatur eu quis reprehenderit velit nostrud deserunt deserunt. Commodo duis esse deserunt laborum tempor dolore anim laborum deserunt ipsum sit tempor consectetur.\r\n", | ||
"registered": "2023-05-27T09:39:08 +04:00", | ||
"latitude": 45.890773, | ||
"longitude": -29.059383, | ||
"tags": [ | ||
"Lorem", | ||
"sunt", | ||
"cillum", | ||
"ea", | ||
"in", | ||
"aute", | ||
"culpa" | ||
], | ||
"friends": [ | ||
{ | ||
"id": 0, | ||
"name": "Jo Nunez" | ||
}, | ||
{ | ||
"id": 1, | ||
"name": "Mcdonald Burns" | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "Pacheco Vang" | ||
} | ||
], | ||
"greeting": "Hello, Amanda Rodgers! You have 7 unread messages.", | ||
"favoriteFruit": "strawberry" | ||
} | ||
]); | ||
``` | ||
|
||
### Output | ||
|
||
```javascript | ||
[ | ||
"66897c0b5bb3f3bda598a7be", | ||
"57cc37b7-ea7b-4cf5-b07e-238a15cc1cdd", | ||
"$1,290.80", | ||
"http://placehold.it/32x32", | ||
"blue", | ||
"Valeria Jenkins", | ||
"female", | ||
"GEOLOGIX", | ||
"[email protected]", | ||
"+1 (976) 597-3338", | ||
"681 Jackson Place, Collins, Nevada, 8477", | ||
"Officia sunt fugiat aute eiusmod cillum excepteur enim consectetur in pariatur consequat cupidatat. Id minim anim sint cupidatat nostrud labore esse proident eiusmod eu. Dolor sit aute adipisicing est proident eiusmod voluptate reprehenderit sunt aliquip non quis. Lorem voluptate laboris aliquip cupidatat.\r\n", | ||
"2016-04-05T01:14:10 +04:00", | ||
"voluptate", | ||
"esse", | ||
"amet", | ||
"mollit", | ||
"in", | ||
"consectetur", | ||
"sunt", | ||
"Moore Howell", | ||
"Summer Cline", | ||
"Francis Simon", | ||
"Hello, Valeria Jenkins! You have 1 unread messages.", | ||
"banana", | ||
"66897c0b0eea9250887803d6", | ||
"6eac3134-b442-4289-a498-ef9b5624f196", | ||
"$1,302.96", | ||
"http://placehold.it/32x32", | ||
"brown", | ||
"Amanda Rodgers", | ||
"female", | ||
"GRAINSPOT", | ||
"[email protected]", | ||
"+1 (987) 457-3247", | ||
"650 Osborn Street, Edenburg, New Jersey, 1377", | ||
"Eu minim enim aliquip nulla aliquip elit sit nostrud dolore reprehenderit aliquip sit qui Lorem. Enim et excepteur dolor velit minim nulla ullamco nisi. Qui adipisicing id occaecat nisi duis quis sint minim laborum minim id. Do id aliqua deserunt incididunt nulla officia nostrud reprehenderit laborum aliquip qui. Veniam pariatur eu quis reprehenderit velit nostrud deserunt deserunt. Commodo duis esse deserunt laborum tempor dolore anim laborum deserunt ipsum sit tempor consectetur.\r\n", | ||
"2023-05-27T09:39:08 +04:00", | ||
"Lorem", | ||
"sunt", | ||
"cillum", | ||
"ea", | ||
"in", | ||
"aute", | ||
"culpa", | ||
"Jo Nunez", | ||
"Mcdonald Burns", | ||
"Pacheco Vang", | ||
"Hello, Amanda Rodgers! You have 7 unread messages.", | ||
"strawberry" | ||
] | ||
``` | ||
|
||
## License | ||
Copyright (c) 2024 Jason Mulligan | ||
Licensed under the BSD-3 license. |
This file contains 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,56 @@ | ||
/** | ||
* tiny-strings | ||
* | ||
* @copyright 2024 Jason Mulligan <[email protected]> | ||
* @license BSD-3-Clause | ||
* @version 1.0.0 | ||
*/ | ||
'use strict'; | ||
|
||
const STRING_STRING = "string"; | ||
const STRING_OBJECT = "object"; | ||
const MSG_INVALID_INPUT = "Argument must be an Array or Object"; | ||
|
||
function strings (arg = {}, keys = false) { | ||
if (typeof arg !== STRING_OBJECT) { | ||
throw new TypeError(MSG_INVALID_INPUT); | ||
} | ||
|
||
const result = []; | ||
|
||
if (Array.isArray(arg)) { | ||
for (const item of arg) { | ||
if (typeof item === STRING_STRING) { | ||
result.push(item); | ||
} else if (typeof item === STRING_OBJECT) { | ||
result.push(...strings(item, keys)); | ||
} | ||
} | ||
} else { | ||
const argKeys = Object.keys(arg); | ||
|
||
if (keys) { | ||
result.push(...argKeys); | ||
} | ||
|
||
for (const key of argKeys) { | ||
if (typeof arg[key] === STRING_STRING) { | ||
result.push(arg[key]); | ||
} else if (Array.isArray(arg[key])) { | ||
for (const value of arg[key]) { | ||
if (typeof value === STRING_OBJECT) { | ||
result.push(...strings(value, keys)); | ||
} else if (typeof value === STRING_STRING) { | ||
result.push(value); | ||
} | ||
} | ||
} else if (typeof arg[key] === STRING_OBJECT) { | ||
result.push(...strings(arg[key], keys)); | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
exports.strings = strings; |
This file contains 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,50 @@ | ||
/** | ||
* tiny-strings | ||
* | ||
* @copyright 2024 Jason Mulligan <[email protected]> | ||
* @license BSD-3-Clause | ||
* @version 1.0.0 | ||
*/ | ||
const STRING_STRING = "string"; | ||
const STRING_OBJECT = "object"; | ||
const MSG_INVALID_INPUT = "Argument must be an Array or Object";function strings (arg = {}, keys = false) { | ||
if (typeof arg !== STRING_OBJECT) { | ||
throw new TypeError(MSG_INVALID_INPUT); | ||
} | ||
|
||
const result = []; | ||
|
||
if (Array.isArray(arg)) { | ||
for (const item of arg) { | ||
if (typeof item === STRING_STRING) { | ||
result.push(item); | ||
} else if (typeof item === STRING_OBJECT) { | ||
result.push(...strings(item, keys)); | ||
} | ||
} | ||
} else { | ||
const argKeys = Object.keys(arg); | ||
|
||
if (keys) { | ||
result.push(...argKeys); | ||
} | ||
|
||
for (const key of argKeys) { | ||
if (typeof arg[key] === STRING_STRING) { | ||
result.push(arg[key]); | ||
} else if (Array.isArray(arg[key])) { | ||
for (const value of arg[key]) { | ||
if (typeof value === STRING_OBJECT) { | ||
result.push(...strings(value, keys)); | ||
} else if (typeof value === STRING_STRING) { | ||
result.push(value); | ||
} | ||
} | ||
} else if (typeof arg[key] === STRING_OBJECT) { | ||
result.push(...strings(arg[key], keys)); | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
}export{strings}; |
This file contains 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,5 @@ | ||
/*! | ||
2024 Jason Mulligan <[email protected]> | ||
@version 1.0.0 | ||
*/ | ||
const o="string",e="object";function r(t={},s=!1){if(typeof t!==e)throw new TypeError("Argument must be an Array or Object");const f=[];if(Array.isArray(t))for(const p of t)typeof p===o?f.push(p):typeof p===e&&f.push(...r(p,s));else{const p=Object.keys(t);s&&f.push(...p);for(const y of p)if(typeof t[y]===o)f.push(t[y]);else if(Array.isArray(t[y]))for(const p of t[y])typeof p===e?f.push(...r(p,s)):typeof p===o&&f.push(p);else typeof t[y]===e&&f.push(...r(t[y],s))}return f}export{r as strings};//# sourceMappingURL=tiny-strings.min.js.map |
Oops, something went wrong.