🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

binary-case

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-case - npm Package Compare versions

Comparing version

to
1.1.4

.idea/markdown-navigator.xml

57

index.js
/**
* @license
* Copyright 2016 Brigham Young University
* Copyright 2018 Brigham Young University
*

@@ -44,3 +44,3 @@ * Licensed under the Apache License, Version 2.0 (the "License");

var index = options.startIndex;
let index = options.startIndex;
return {

@@ -73,3 +73,3 @@ next: function() {

const max = binaryCase.maxNumber(string);
for (var i = 0; i <= max; i++) {
for (let i = 0; i <= max; i++) {
results.push(binaryCase(string, i));

@@ -80,33 +80,32 @@ }

/**
* A performance improved method for acquiring the binary case, provided by Blake Embrey with very minor modification by James Speirs.
* @author Blake Embrey | https://github.com/blakeembrey
* @author James Speirs | https://github.com/gi60s
* @param {string} str
* @param {number} val
* @returns {string}
*/
function getBinaryCase (str, val) {
let res = '';
function getBinaryCase(string, number) {
const binary = (number >>> 0).toString(2);
for (let i = 0; i < str.length; i++) {
const code = str.charCodeAt(i);
var bin;
var ch;
var i;
var j = binary.length - 1;
var offset;
var result = '';
for (i = 0; i < string.length; i++) {
ch = string.charAt(i);
if (/[a-z]/ig.test(ch)) {
bin = binary.charAt(j--);
if (bin === '1') {
offset = ch >= 'a' && ch <= 'z' ? -32 : 32;
result += String.fromCharCode(ch.charCodeAt(0) + offset);
} else {
result += ch;
}
if (j < 0) {
result += string.substr(i + 1);
break;
}
if (code >= 65 && code <= 90) {
res += val & 1 ? String.fromCharCode(code + 32) : String.fromCharCode(code);
val >>>= 1;
} else if (code >= 97 && code <= 122) {
res += val & 1 ? String.fromCharCode(code - 32) : String.fromCharCode(code);
val >>>= 1;
} else {
result += ch;
res += String.fromCharCode(code);
}
if (val === 0) {
return res + str.substr(i + 1);
}
}
return result;
return res;
}
{
"name": "binary-case",
"version": "1.1.3",
"version": "1.1.4",
"description": "Take a string and a number and perform binary case switching on alpha characters.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -68,2 +68,13 @@ /**

t.equal(binaryCase('A 123BC', 0), 'A 123BC', 'no change');
t.equal(binaryCase('A 123BC', 1), 'a 123BC', 'first char');
t.equal(binaryCase('A 123BC', 2), 'A 123bC', 'second char');
t.equal(binaryCase('A 123BC', 3), 'a 123bC', 'first and second char');
t.equal(binaryCase('A 123BC', 4), 'A 123Bc', 'third char');
t.equal(binaryCase('A 123BC', 5), 'a 123Bc', 'first and third char');
t.equal(binaryCase('A 123BC', 6), 'A 123bc', 'second and third char');
t.equal(binaryCase('A 123BC', 7), 'a 123bc', 'all chars');
t.equal(binaryCase('A 123BC', 8), binaryCase('A 123BC', 0), 'duplicate');
t.equal(binaryCase('A 123BC', 8, noOverflow), false, 'unable to modify');
t.equal(binaryCase('Abc', 1), 'abc', 'toggle case');

@@ -70,0 +81,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet