gensequence
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "gensequence", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Small library to simplify working with Generators and Iterators in Javascript / Typescript", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -7,8 +7,13 @@ # GenSequence | ||
The purpose of this library is to make using the result of a generator easier to use. It is not intended as a replacement for array and | ||
the convenient [...genFn()] notation. GenSequence is useful for cases where you might not was an array of all possible values. | ||
The purpose of this library is to make using the results of a generator function easier. | ||
It is not intended as a replacement for arrays and the convenient [...genFn()] notation. | ||
GenSequence is useful for cases where you might not want an array of all possible values. | ||
GenSequence deals effeciently with large sequences because only one element at a time is evaluated. | ||
Intermediate arrays are not created, saving memory and cpu cycles. | ||
## Installation | ||
`npm install -S gensequence` | ||
``` | ||
npm install -S gensequence | ||
``` | ||
@@ -18,9 +23,15 @@ ## Usage | ||
### Javascript | ||
`import GenSequence from "GenSequence";` | ||
``` | ||
import GenSequence from "gensequence"; | ||
``` | ||
or | ||
`import { GenSequence } from "GenSequence";` | ||
``` | ||
import { GenSequence } from "gensequence"; | ||
``` | ||
### Typescript | ||
`import {GenSequence} from 'GenSequence';` | ||
``` | ||
import {GenSequence} from 'gensequence'; | ||
``` | ||
@@ -61,3 +72,3 @@ ## Examples | ||
Regular expressions are wonderfully powerful. Yes, working with the results can sometimes be a bit of a pain. | ||
Regular expressions are wonderfully powerful. Yet, working with the results can sometimes be a bit of a pain. | ||
@@ -73,2 +84,3 @@ ```javascript | ||
/* return a sequence of matched text */ | ||
function match(reg: RegExp, text: string) { | ||
@@ -80,2 +92,3 @@ return GenSequence(execRegEx(reg, text)) | ||
/* extract words out of a string of text */ | ||
function matchWords(text: string) { | ||
@@ -85,3 +98,4 @@ return GenSequence(match(/\w+/g, text)); | ||
export function toSetOfWords(text: string) { | ||
/* convert some text into a set of unique words */ | ||
function toSetOfWords(text: string) { | ||
// GenSequence can be used directly with a Set or Match | ||
@@ -91,6 +105,6 @@ return new Set(matchWords(text)); | ||
export const text = 'Some long bit of text with many words, duplicate words...'; | ||
export const setOfWords = toSetOfWords(text); | ||
const text = 'Some long bit of text with many words, duplicate words...'; | ||
const setOfWords = toSetOfWords(text); | ||
// Walk through the set of words and pull out the 4 letter one. | ||
export const setOf4LetterWords = new Set(GenSequence(setOfWords).filter(a => a.length === 4)); | ||
const setOf4LetterWords = new Set(GenSequence(setOfWords).filter(a => a.length === 4)); | ||
@@ -97,0 +111,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44787
125