New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

glitched-writer

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glitched-writer - npm Package Compare versions

Comparing version 2.0.9 to 2.0.10

12

lib/char.d.ts

@@ -10,3 +10,4 @@ import GlitchedWriter from './index';

stop: boolean;
special: boolean;
instant: boolean;
isWhitespace: boolean;
els?: {

@@ -18,4 +19,5 @@ charEl: HTMLSpanElement;

};
constructor(l: string, gl: string, writer: GlitchedWriter, initialGhosts?: string, special?: boolean);
reset(l: string, gl: string, initialGhosts?: string, special?: boolean): void;
constructor(writer: GlitchedWriter, l: string, gl: string, initialGhosts?: string, instant?: boolean);
private setProps;
reset(l: string, gl: string, initialGhosts?: string, instant?: boolean): void;
get string(): string;

@@ -28,4 +30,4 @@ get finished(): boolean;

step(): void;
addGhost(): void;
removeGhost(): void;
private addGhost;
private removeGhost;
}

@@ -5,16 +5,11 @@ "use strict";

class Char {
constructor(l, gl, writer, initialGhosts, special = false) {
constructor(writer, l, gl, initialGhosts = '', instant = false) {
this.ghostsBefore = [];
this.ghostsAfter = [];
this.stop = false;
this.l = l;
this.gl = gl;
this.instant = false;
this.isWhitespace = false;
this.writer = writer;
this.special = special;
if (initialGhosts)
this.ghostsBefore = [...initialGhosts];
this.stepsLeft = writer.options.stepsLeft;
if (special)
this.stepsLeft = 0;
else if (writer.options.letterize) {
this.setProps(l, gl, initialGhosts, instant);
if (writer.options.letterize) {
this.els = {

@@ -34,10 +29,14 @@ charEl: document.createElement('span'),

}
reset(l, gl, initialGhosts = '', special = false) {
if (!special && this.special)
this.l = '';
setProps(l, gl, initialGhosts = '', instant = false) {
this.l = l;
this.gl = gl;
this.special = special;
this.ghostsBefore = Array.from(initialGhosts);
this.instant = instant;
this.ghostsBefore = [...initialGhosts];
this.stepsLeft = this.writer.options.stepsLeft;
if (instant)
this.stepsLeft = 0;
this.isWhitespace = utils_1.isSpecialChar(l);
}
reset(l, gl, initialGhosts = '', instant = false) {
this.setProps(l, gl, initialGhosts, instant);
this.writeToElement();

@@ -48,3 +47,2 @@ if (this.els) {

}
document.createDocumentFragment;
}

@@ -62,9 +60,9 @@ get string() {

return;
const { l, ghostsBefore, ghostsAfter } = this, { ghostsBeforeEl, ghostsAfterEl, letterEl: letter } = this.els;
const { l } = this, { ghostsBeforeEl, ghostsAfterEl, letterEl } = this.els;
if (this.writer.options.html)
letter.innerHTML = l;
letterEl.innerHTML = l;
else
letter.textContent = l;
ghostsBeforeEl.textContent = ghostsBefore.join('');
ghostsAfterEl.textContent = ghostsAfter.join('');
letterEl.textContent = l;
ghostsBeforeEl.textContent = this.ghostsBefore.join('');
ghostsAfterEl.textContent = this.ghostsAfter.join('');
}

@@ -78,3 +76,3 @@ appendChild() {

let interval = this.writer.options.genInterval;
if (this.gl === '' || this.gl === ' ')
if (this.isWhitespace)
interval /= 2;

@@ -84,4 +82,5 @@ return interval;

async type() {
var _a, _b, _c, _d;
const loop = async () => {
!this.special && (await utils_1.wait(this.interval));
!this.instant && (await utils_1.wait(this.interval));
this.step();

@@ -92,10 +91,9 @@ this.writer.emiter.call('step');

};
!this.special && (await utils_1.wait(this.writer.options.genInitDelay));
if (this.els)
this.els.charEl.classList.add('gw-typing');
!this.instant && (await utils_1.wait(this.writer.options.genInitDelay));
(_a = this.els) === null || _a === void 0 ? void 0 : _a.charEl.classList.add('gw-typing');
await utils_1.promiseWhile(() => !this.finished && !this.writer.state.isPaused && !this.stop, loop);
if (this.els && this.finished) {
this.els.charEl.classList.add('gw-finished');
this.els.charEl.classList.remove('gw-typing');
this.els.letterEl.classList.remove('gw-glitched');
if (this.finished) {
(_b = this.els) === null || _b === void 0 ? void 0 : _b.charEl.classList.add('gw-finished');
(_c = this.els) === null || _c === void 0 ? void 0 : _c.charEl.classList.remove('gw-typing');
(_d = this.els) === null || _d === void 0 ? void 0 : _d.letterEl.classList.remove('gw-glitched');
}

@@ -105,7 +103,9 @@ return this.finished;

step() {
if (this.stepsLeft > 0 && this.l !== this.gl) {
var _a, _b;
const { ghostChance, changeChance } = this.writer.options;
if ((this.stepsLeft > 0 && this.l !== this.gl) ||
utils_1.coinFlip((ghostChance + changeChance) / 3.5)) {
/**
* IS GROWING
*/
const { ghostChance, changeChance } = this.writer.options;
if (utils_1.coinFlip(ghostChance)) {

@@ -118,4 +118,3 @@ if (this.writer.state.ghostsInLimit)

if (utils_1.coinFlip(changeChance)) {
if (this.els)
this.els.letterEl.classList.add('gw-glitched');
(_a = this.els) === null || _a === void 0 ? void 0 : _a.letterEl.classList.add('gw-glitched');
this.l = this.writer.options.genGhost;

@@ -128,4 +127,3 @@ }

*/
if (this.els)
this.els.letterEl.classList.remove('gw-glitched');
(_b = this.els) === null || _b === void 0 ? void 0 : _b.letterEl.classList.remove('gw-glitched');
this.l = this.gl;

@@ -132,0 +130,0 @@ this.removeGhost();

@@ -12,3 +12,3 @@ "use strict";

var _a, _b;
const { htmlElement, writerData, string } = this.writer;
const { htmlElement, writerData } = this.writer, string = eventType === 'finish' ? this.writer.goalString : this.writer.string;
if (htmlElement && !this.writer.options.letterize) {

@@ -15,0 +15,0 @@ if (this.writer.options.html)

@@ -28,3 +28,2 @@ import Options from './options';

private removeExtraChars;
private removeSpecialChars;
private setChar;

@@ -31,0 +30,0 @@ private get goalStringArray();

@@ -5,3 +5,2 @@ "use strict";

// eslint-disable-next-line import/no-extraneous-dependencies
const lodash_1 = require("lodash");
const options_1 = require("./options");

@@ -35,6 +34,6 @@ const state_1 = require("./state");

get previousString() {
var _a, _b;
let prev = (_b = (_a = this.htmlElement) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : this.string;
if (this.options.html)
prev = utils_1.filterHtml(prev);
var _a;
let prev = (_a = this.htmlElement) === null || _a === void 0 ? void 0 : _a.textContent;
if (typeof prev !== 'string')
prev = this.options.html ? utils_1.filterHtml(this.string) : this.string;
prev = prev.trim();

@@ -71,3 +70,3 @@ return prev;

this.options.setCharset();
this.removeSpecialChars();
// this.removeSpecialChars()
if (this.options.startFrom === 'matching')

@@ -99,3 +98,3 @@ this.createMatchingCharTable();

// console.table(
// this.charTable.map(({ ghostsBefore, ghostsAfter, l, gl, special }) => [
// this.charTable.map(({ ghostsBefore, ghostsAfter, l, gl, instant }) => [
// ghostsBefore.join(''),

@@ -105,3 +104,3 @@ // ghostsAfter.join(''),

// gl,
// special && 'HTML',
// instant && 'HTML',
// ]),

@@ -150,3 +149,2 @@ // )

const pl = previous[pi];
let isWhitespace = false;
if (gl.type === 'tag') {

@@ -157,5 +155,4 @@ pi--;

}
isWhitespace = utils_1.isSpecialChar(gl.value);
const fi = gl.value !== '' ? previous.indexOf(gl.value, pi) : -1;
if (fi !== -1 && fi - pi <= maxDist && !isWhitespace) {
if (fi !== -1 && fi - pi <= maxDist) {
const appendedText = previous.substring(pi, fi);

@@ -167,3 +164,3 @@ this.setChar(gi, gl.value, gl.value, appendedText);

else
this.setChar(gi, pl || this.options.space, gl.value || this.options.space, '', isWhitespace);
this.setChar(gi, pl || this.options.space, gl.value || this.options.space);
});

@@ -183,3 +180,3 @@ this.removeExtraChars(goalStringArray.length);

}
this.setChar(gi, pl, gl.value, undefined, utils_1.isSpecialChar(gl.value));
this.setChar(gi, pl, gl.value);
});

@@ -195,13 +192,13 @@ this.removeExtraChars(goalStringArray.length);

}
removeSpecialChars() {
let i = lodash_1.findLastIndex(this.charTable, 'special');
while (i !== -1) {
this.charTable.splice(i, 1);
i = lodash_1.findLastIndex(this.charTable, 'special');
}
}
// private removeSpecialChars() {
// let i: number = findLastIndex(this.charTable, 'special')
// while (i !== -1) {
// this.charTable.splice(i, 1)
// i = findLastIndex(this.charTable, 'special')
// }
// }
setChar(ci, pl, gl, appendedText, special = false) {
const { charTable } = this, char = charTable[ci];
if (special) {
charTable.splice(ci, 0, new char_1.default(pl, gl, this, '', true));
charTable.splice(ci, 0, new char_1.default(this, pl, gl, '', true));
return;

@@ -211,3 +208,3 @@ }

? char.reset(pl, gl, appendedText, special)
: charTable.push(new char_1.default(pl, gl, this, appendedText, special));
: charTable.push(new char_1.default(this, pl, gl, appendedText, special));
}

@@ -214,0 +211,0 @@ get goalStringArray() {

@@ -13,3 +13,3 @@ import { ConstructorOptions, OptionsFields, RangeOrNumber } from './types';

glyphsFromString: boolean;
ghostCharset: string;
ghostCharset: string[];
oneAtATime: boolean;

@@ -16,0 +16,0 @@ html: boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// eslint-disable-next-line import/no-extraneous-dependencies
const lodash_1 = require("lodash");
const utils_1 = require("./utils");

@@ -22,3 +21,3 @@ const presets_1 = require("./presets");

(_h = options.glyphsFromString) !== null && _h !== void 0 ? _h : presets_1.presets.default.glyphsFromString;
this.ghostCharset = this.glyphs;
this.ghostCharset = [...this.glyphs];
this.oneAtATime = (_j = options.oneAtATime) !== null && _j !== void 0 ? _j : presets_1.presets.default.oneAtATime;

@@ -54,3 +53,3 @@ this.html = (_k = options.html) !== null && _k !== void 0 ? _k : presets_1.presets.default.html;

var _a;
return (_a = lodash_1.sample(this.ghostCharset)) !== null && _a !== void 0 ? _a : '';
return (_a = utils_1.getRandom(this.ghostCharset)) !== null && _a !== void 0 ? _a : '';
}

@@ -64,5 +63,5 @@ setCharset() {

: this.writer.goalString));
this.ghostCharset = charset;
this.ghostCharset = [...charset].filter(l => !['\t', '\n', '\r', '\f', '\v'].includes(l));
}
}
exports.default = Options;

@@ -50,6 +50,6 @@ "use strict";

terminal: {
interval: 30,
interval: [25, 35],
initialDelay: [0, 0],
steps: 0,
changeChance: 1,
changeChance: 0.5,
maxGhosts: 0,

@@ -65,3 +65,3 @@ glyphs: '',

interval: [10, 35],
steps: [0, 42],
steps: [0, 30],
maxGhosts: 4.6,

@@ -68,0 +68,0 @@ changeChance: 0.5,

import { RangeOrNumber } from './types';
export declare function random(min: number, max: number, math?: 'floor' | 'round' | 'ceil'): number;
export declare function deleteRandom(array: any[]): void;
export declare function getRandom<T>(iterable: Array<T>): T;
export declare function getRandom(iterable: string): string;
export declare function filterDuplicates(iterable: string): string;
export declare function filterDuplicates<T>(iterable: Array<T>): Array<T>;
export declare function parseCharset(input?: string | string[] | Set<string>): string | undefined;
export declare function deleteRandom(array: any[]): void;
export declare const wait: (time: number) => Promise<number>;

@@ -16,8 +18,8 @@ export declare function promiseWhile(conditionFunc: () => boolean, actionPromise: () => Promise<any>): Promise<void>;

value: string;
type?: 'tag' | 'html_entity';
type?: 'tag' | 'html_entity' | 'whitespace';
};
export declare const letterToLetterItem: (string: string) => LetterItem;
export declare const stringToLetterItems: (string: string | string[]) => LetterItem[];
export declare const isSpecialChar: (l: string) => boolean;
export declare function htmlToArray(string: string): LetterItem[];
export declare function filterHtml(string: string): string;
export declare const isSpecialChar: (l: string) => boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSpecialChar = exports.filterHtml = exports.htmlToArray = exports.stringToLetterItems = exports.letterToLetterItem = exports.coinFlip = exports.getRandomFromRange = exports.animateWithClass = exports.isInRange = exports.arrayOfTheSame = exports.promiseWhile = exports.wait = exports.deleteRandom = exports.parseCharset = exports.filterDuplicates = exports.random = void 0;
exports.filterHtml = exports.htmlToArray = exports.isSpecialChar = exports.stringToLetterItems = exports.letterToLetterItem = exports.coinFlip = exports.getRandomFromRange = exports.animateWithClass = exports.isInRange = exports.arrayOfTheSame = exports.promiseWhile = exports.wait = exports.parseCharset = exports.filterDuplicates = exports.getRandom = exports.deleteRandom = exports.random = void 0;
/* eslint-disable no-unused-vars */

@@ -21,2 +21,11 @@ function random(min, max, math) {

exports.random = random;
function deleteRandom(array) {
const { length } = array;
array.splice(random(0, length, 'floor'), 1);
}
exports.deleteRandom = deleteRandom;
function getRandom(iterable) {
return iterable[random(0, iterable.length, 'floor')];
}
exports.getRandom = getRandom;
function filterDuplicates(iterable) {

@@ -44,7 +53,2 @@ const isString = typeof iterable === 'string', result = [];

exports.parseCharset = parseCharset;
function deleteRandom(array) {
const { length } = array;
array.splice(random(0, length, 'floor'), 1);
}
exports.deleteRandom = deleteRandom;
const wait = (time) => new Promise(resolve => setTimeout(() => resolve(time), time));

@@ -82,2 +86,4 @@ exports.wait = wait;

exports.stringToLetterItems = stringToLetterItems;
const isSpecialChar = (l) => ['\t', '\n', '\r', '\f', '\v', ' ', ''].includes(l);
exports.isSpecialChar = isSpecialChar;
const findHTMLPattern = '(&#?[0-9a-zA-Z]{2,6};)|(<style.+?>.+?</style>|<script.+?>.+?</script>|<(?:!|/?[a-zA-Z]+).*?/?>)';

@@ -100,2 +106,10 @@ function htmlToArray(string) {

resultArray.push(...exports.stringToLetterItems(string.slice(lastIndex)));
// return resultArray.map(l =>
// l.type
// ? l
// : {
// value: l.value,
// type: isSpecialChar(l.value) ? 'whitespace' : undefined,
// },
// )
return resultArray;

@@ -109,3 +123,1 @@ }

exports.filterHtml = filterHtml;
const isSpecialChar = (l) => ['\t', '\n', '\r', '\f', '\v'].includes(l);
exports.isSpecialChar = isSpecialChar;
{
"name": "glitched-writer",
"version": "2.0.9",
"description": "Glitched, text writing module. Highly customizable settings. Decoding, decrypting, scrambling, and simply spelling text. For web and node.",
"version": "2.0.10",
"description": "Glitched, text writing module. Highly customizable settings. Decoding, decrypting, scrambling, and simply spelling text.",
"author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",

@@ -22,8 +22,4 @@ "license": "MIT",

},
"dependencies": {
"lodash.findlastindex": "^4.6.0",
"lodash.sample": "^4.2.1"
},
"devDependencies": {
"@parcel/transformer-sass": "^2.0.0-beta.2",
"@parcel/transformer-sass": "2.0.0-beta.2",
"@types/jsdom": "^16.2.7",

@@ -30,0 +26,0 @@ "@types/lodash.findlastindex": "^4.6.6",

@@ -34,4 +34,4 @@ # Glitched Writer

1. [Installation](#installation)
2. [Usage](#usage)
1. **[Installation](#installation)**
2. **[Usage](#usage)**
- [Creating Class Instance](#creating-class-instance)

@@ -47,4 +47,4 @@ - [Writing](#writing)

- [Available imports](#available-imports)
3. [Presets](#presets)
4. [Options](#customizing-options)
3. **[Presets](#presets)**
4. **[Options](#customizing-options)**

@@ -70,3 +70,3 @@ ---

```html
<script src="https://cdn.jsdelivr.net/npm/glitched-writer@2.0.7/lib/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/glitched-writer@2.0.10/lib/index.min.js"></script>
```

@@ -73,0 +73,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc